gpt4 book ai didi

java - 使用 jython 在 Python 中实例化对象与 Java 相同

转载 作者:行者123 更新时间:2023-12-02 05:33:09 26 4
gpt4 key购买 nike

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com