在Java中,我能够运行我的代码: (这只是示例命名)
import com.projectname.api.APIOne;
import com.projectname.api.APITwo;
import com.projectname.api.APIThree;
import com.projectname.api.APIFour;
import com.projectname.api.MainAPI;
public class TestMain {
public static void main(String[] args) {
APIOne a = APIOne.getName();
APITwo b = APIThree.getAddress();
APIFour d = b.getEmail();
MainAPI mainapi = new MainAPI();
mainapi.setEmail(d)
}
}
它运行正常,我尝试将其转换为Python:
import com.projectname.api.APIOne as APIOne;
import com.projectname.api.APITwo as APITwo;
import com.projectname.api.APIThree as APIThree;
import com.projectname.api.APIFour as APIFour;
def test():
a = APIOne.getName();
b = APIThree.getAddress();
d = b.getEmail();
mainapi = MainAPI();
mainapi.setEmail(d)
test()
但是这是正确的实例化方式吗?这让我对实例化感到困惑。
希望你能帮助我。
最佳答案
从java包或python模块导入类通常写为:
from java.lang import Math
而不是:
import java.lang.Math as Math
但是,您的代码是正确的。
关于java - 使用 jython 在 Python 中实例化对象与 Java 相同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25312546/