This does not work, because T can be of any type, and Java is statically typed. The compiler does not know if you are trying to create a SceneNode<String> - what would execute do?
One option is to create an appropriate interface, for example
public interface Executable { void execute(); }
and then restrict T to SceneNode to implement Executable :
public class SceneNode<T extends Executable> { ... }
(I find it a little strange that T should extend Executable , and not implement it in the source code, but then T may turn out to be the interface itself, so I think it makes sense.)
Then it should work fine. Of course, you could make Executable abstract superclass - or even a (not finite) concrete class - if you want, but I usually prefer to use an interface if I had no reason to.
Jon skeet
source share