0
Why java so confusing
What is this in java Classname.method( new class(String A){ // Is there class override } );
3 Antworten
+ 2
<class name>.method() is used within reflections. But the notation on your code snippet looks strange for me.
Btw. reflections are no stuff for beginners.
+ 1
if you mean:
new ClassName2("some string"){}
it is the declaration of the anonymous class derived from the class ClassName2. It passes data to a constructor.
In the example below it also extends getData() method.
public class Program {
public static void main(String[] args) {
ClassName.method(
new ClassName2("some string") {
String getData() { //overriding method
System.out.println(data);
return data;
}
}
); //.method();
} }
class ClassName {
static void method(ClassName2 obj){
String s = obj.getData();
} }
class ClassName2 {
String data;
ClassName2(String data){ this.data = data;}
String getData(){ return data; };
}
0
Thanks zemiak finally got it