How created method with signature as List

Posted by London on Stack Overflow See other posts from Stack Overflow or by London
Published on 2010-05-17T14:30:52Z Indexed on 2010/05/17 14:40 UTC
Read the original article Hit count: 259

Filed under:

Hi all, I'm very new to Java programming language so this is probably dumb question but I have to ask it because I can't figure it out on my own. Here is the deal.

I want to create method which extracts certain object type from a list. So the method should receive List as argument, meaning list should contain either Object1 or Object2. I've tried like this :

   public Object1 extractObject(List<?>){
    //some pseudo-code 
   ... loop trough list and check if list item is instance of object one return that instance
    }

The problem with declaring method with List<?> as method argument is that I receive compilation error from eclipse Syntax error on token ">", VariableDeclaratorId expected after this token.

How do I set the method signature properly to accept object types either Object1 or Object2 ? Thank you

© Stack Overflow or respective owner

Related posts about java