Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

13
  • 8
    Member variables are not polymorphic in Java (whether static or non-static). The best you could do is indeed use reflection, but there's probably a better way to achieve whatever the overall goal is here. Commented May 26, 2014 at 22:01
  • They're not polymorphic? Commented May 26, 2014 at 22:01
  • No, only non-static methods are. Commented May 26, 2014 at 22:02
  • 1
    No, they're not. You have to change your design. Commented May 26, 2014 at 22:02
  • 3
    How about defining an Interface HasI with a getI() method and making A, B, and C implement HasI? Your compare will be public int comapre(HasI a, HasI b) Commented May 26, 2014 at 22:06