KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
How to find out if a method is overridden by child classes? For example, public class Test { static public class B { public String m() {return "From B";}; } static public class B1 extends B { } static public class B2 extends B { public String m() {return "from B2";}; } /** * @param args * @throws FileNotFoundException */ public static void main(String[] args) { B b1 = new B1(); System.out.println("b1 = " + b1.m()); B b2 = new B2(); System.out.println("b1 = " + b2.m()); } } Given an instance of B, how do I know if any derived classes have overridden method m() like B2? Update: My question wasn't clear. Actually, I was trying to ask if this is possible without resorting to reflection. This check is done in a tight loop and it's used in a performance hack to save a few CPU cycles.
Tags (comma-separated)
Save Edits
Cancel