• Post Reply Bookmark Topic Watch Topic
  • New Topic

Wildcard parameters for abstract methods  RSS feed

 
Larry Homes
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have an abstract class that contains an abstract method. I want to force all classes that derive from this abstract to use this method but I do not care what parameters they use.

Here is some example code to make it clearer



I do not want to force any classes that implment this class to use a String in the parameter, but they have to have a match method. So basically what I am looking for is a wildcard like I put in the generic for the ArrayList<?> above.

Is there any way I can achieve or emulate this?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37513
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Larry,
Do you want the parameter to be any object or the same object that is returned by the method?
 
Larry Homes
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No it can be any object or primative.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make the class parameterized:

A subclass that should match on String should then be declared as this:

This does not work for primitives though, but you can use their wrapper types instead.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!