In Java I was able to run my code as: (This are just sample naming)
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)
}
}
It is running okay, I tried converting this to Python as:
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()
But is this the right way of instantiating? It make me confuse on instantiating.
Hope you could help me.
2 Answers 2
Importing a class from a java package or python module is normally written as:
from java.lang import Math
Rather than:
import java.lang.Math as Math
But, your code is correct.
answered Aug 14, 2014 at 19:29
Dunes
42.2k7 gold badges87 silver badges107 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
I don't understand why you are confused, but this is correct, you could check the Jython documentation about instantiating Java objects using Jython and instantiates the objects the same way as you do.
answered Aug 14, 2014 at 16:25
enrico.bacis
31.9k10 gold badges90 silver badges116 bronze badges
Comments
default
TestMain?