java - Generics: Type not applicable for arguments -


using generics compiler should infer type of object t during runtime, giving me static violation stated in title , can't figure out (using other questions) fix problem.

here method:

public static <t> boolean linearsearchiterative(t[] array, t obj) {     for(int = 0; < array.length; i++) {         if(array[i].equals(obj)) {             return true;         }     }     return false; } 

here how declare in main method:

int x[] = {2, 3, 5, 6, 1}; int y = 1; system.out.println(linearsearch.linearsearchiterative(x, y)); 

generics in java work reference types, not primitive types.

change running code to:

byte x[] = {2, 3, 5, 6, 1}; // or integer byte y   = 1;               // or integer 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -