How do I make the method return type generic?

前端 未结 19 2755
無奈伤痛
無奈伤痛 2020-11-22 06:16

Consider this example (typical in OOP books):

I have an Animal class, where each Animal can have many friends.
And subclasses like

19条回答
  •  野的像风
    2020-11-22 06:41

    I did the following in my lib kontraktor:

    public class Actor {
        public SELF self() { return (SELF)_self; }
    }
    

    subclassing:

    public class MyHttpAppSession extends Actor {
       ...
    }
    

    at least this works inside the current class and when having a strong typed reference. Multiple inheritance works, but gets really tricky then :)

提交回复
热议问题