You can create an interface like this:
interface MyAnonymous {
MyAnonymous open();
MyAnonymous dis();
}
new MyAnonymous(){
public MyAnonymous open(){
return this;
}
public MyAnonymous dis(){
return this;
}
}.open().dis();
EDIT ----
As @Jeff points out, an interface is only needed if a link is assigned. In fact, the following solution is true (called by @JamesB):
new MyObject(){
public MyObject open(){
return this;
}
public MyObject dis(){
return this;
}
}.open().dis();
but this did not compile:
MyObject myObject = new MyObject(){
public MyObject open(){
return this;
}
public MyObject dis(){
return this;
}
};
myObject.open().dis();