Package pkg;
/** * Created by Sanmao on 2016/6/29. * * public class Static {/** * from the previous blog with restricted wildcard characters, we see that the Totalarea method is a generic method because it can receive different parameters * But there is no specific type of parameter table, as Generic
In the declaration of the Meorycell class, sometimes a particular type is important. * This may be because of the following reasons * 1. This particular type is used as the return type * 2. This type is for declaring a local variable * 3. This type acts on an extra type parameter * If so, you must declare a display generic method with several types of parameters * as the following code shows a generic static method that makes a series of lookups of value X in array arr by using a generic method * instead of using object as a non-pan method, we can get compile-time error when looking up an Apple object in an array of objects * Generic methods are particularly like generic classes, because type parameter tables can use the same syntax, and before the type parameters in the generic method are in the return type * @param args/P Ublic static void Main (string[] args) {//static s=new static ();
Non-static methods need to invoke object leixing lx1=new leixing (1,2);
Leixing lx2=new leixing (3,4);
Leixing[] Lx=new leixing[]{lx1,lx2};
System.out.println (Static.contains (LX,LX2)); System.out.println (S.contains (LX, lx2)); Non-static methods need to invoke object} public static <AnyType> Boolean contains (anytype[] Arr,anytype x) {//public &L T Anytype> Boolean contains (anytype[] Arr,anytype x) {//Declare non-static object int z=0;
for (AnyType Val:arr) {z++;
if (X.equals (val)) {System.out.println (z);
return true;
return false;
}//So write leixing is not an internal class, the inner class is not in the public class Main method of the new Leixing (), The outer class can class leixing{int x;
int y;
Public leixing () {};
Public leixing (int x,int y) {this.x=x;
This.y=y;
public int GetX () {return x;
public int GetY () {return y; }
}