I'm currious why the following does create a subclass of the original class, changing the class' signature. (Here's a demo)
class Rextester
{
private final T2 t1;
private final T2 t2;
public static void main(String[] args) {
new Rextester().test();
}
Rextester () {
t1 = new T2() {{
setFoo("foo");
setBar("bar");
}};
t2 = new T2() ;
t2.setBar("bar");
t2.setFoo("foo");
}
private void test() {
System.out.println("t1: " + t1.getClass()); // class Rextester$1
System.out.println("t2: " + t2.getClass()); // class T2
}
}
class T2 {
private String foo;
private String bar;
public String getFoo() {
return foo;
}
public void setFoo(String foo) {
this.foo = foo;
}
public String getBar() {
return bar;
}
public void setBar(String bar) {
this.bar = bar;
}
}
Why does t1
become a subclass of Rextester, while t2
stays what it should be?
What good does this bring?