Is there a way in Java to set a “pre-defined” method, I don’t know how to name it, otherwise I have search on Google. Let me explain with an example:
class Class1 {
public int getMyInt() {
[...some calculations...]
return <some number>;
}
}
class Main {
Class1 c1 = new Class1();
(*) int a = 10 + c1;
}
Clearly in line (*) there is a compilation error, I should write int a = 10 + c1.getMyInt()
. My question is this: is it possible in Java to declare the getMyInt
method a pre-defined method so that if I omit the method ina call, the compiler will just call that pre-defined method?