Reputation: 10834
i want to create some simple wrapper classes for an existing class library. To make the syntax nice to read AND nice to guess (via code completion) i'd like to remove the methods of java.lang.Object.
The problem is that all non-atomic things in java inherit from Object and thus have these methods. I already tried to create the wrapper syntax via enums and interfaces, without success; because enums and interfaces are also java.lang.Objects.
java.lang.Object has nine methods that i don't want to see in the code completion of my interfaces. Here's what i want to remove (red) and what i want to keep (green):
alt text http://ju.venile.de/upload/java-lang-object-methods.png
Here is some example code for creating nice wrappers around existing classes (Builder pattern):
public interface IMySyntax{
public IMySyntax myMethod1();
public IMySyntax myMethod2();
}
public class MyBuilder implements IMySyntax{
public static IMySyntax build(){ return (IMySyntax) new MyBuilder() }
public IMySyntax myMethod1(){ /* do something */ return (IMySyntax) this }
public IMySyntax myMethod2(){ /* do something */ return (IMySyntax) this }
}
Usage of the new wrapper code should look like this:
MyBuilder.build()
.myMethod1()
.myMethod2();
Casting all this
statements of the builder to an interface will reduce the method visibility, e.g. if the builder implements more that one interface. All java.lang.Object methods will stay, unfortunately.
If this method hiding was possible in Java (maybe using Annotations?), i could create a nice library that is IDE agnostic (nice code completion everywhere). If not, than maybe there's a trick for at least the Eclipse IDE (maybe a plugin?) that can provide java.lang.Object method hiding.
Upvotes: 8
Views: 3154
Reputation: 10880
For Eclipse 3.4 at least you can do the following:
1) Go to Preferences -> Java -> Appearance -> Type Filters
2) Click Add, and enter java.lang.Object
Now in code assist, the methods inherited directly from java.lang.Object
will dissapear
Upvotes: 29