Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

generics Interface in java

/*In similar way, we can create generic interfaces in java. We can also have multiple type parameters as in Map interface. Again we can provide parameterized value to a parameterized type also, for example new HashMap<String, List<String>>(); is valid.*/
package java.lang;
import java.util.*;

public interface Comparable<T> {
    public int compareTo(T o);
}
Comment

generics Interface in java

/*Suppose we want to restrict the type of objects that can be used in the parameterized type, for example in a method that compares two objects and we want to make sure that the accepted objects are Comparables. To declare a bounded type parameter, list the type parameter’s name, followed by the extends keyword, followed by its upper bound, similar like below method.

The invocation of these methods is similar to unbounded method except that if we will try to use any class that is not Comparable, it will throw compile-time error.

Bounded type parameters can be used with methods as well as classes and interfaces.

Java Generics supports multiple bounds also, i.e <T extends A & B & C>. In this case, A can be an interface or class. If A is class then B and C should be an interface. We can’t have more than one class in multiple bounds.*/
public static <T extends Comparable<T>> int compare(T t1, T t2){
		return t1.compareTo(t2);
	}
Comment

PREVIOUS NEXT
Code Example
Java :: java hashmap replace 
Java :: why string is immutable in java 
Java :: Java short Keyword 
Java :: calculating the percentile in java 
Java :: properties object using a file 
Java :: set array length java 
Java :: javafx listview of objects 
Java :: javafx 
Java :: " meaning in java 
Java :: output folder director 
Java :: java loop find index 
Java :: if else bedingungen java 
Java :: how to change default port in spring boot 
Java :: foreach() java 
Java :: connect as SYSDBA java 
Java :: get sha1 key from keystore 
Java :: Note: flutterpluginspathproviderPathProviderPlugin.java uses unchecked or unsafe operations. 
Java :: power of a number in java 
Java :: how to solve CopyBuffer from HiLo failed, no data 
Java :: What is Java? 
Java :: csv file data structure java 
Java :: viewresolver in spring boot 
Java :: An exception occurred processing JSP page /Home.jsp 
Java :: computeifabsent hashmap java 
Java :: change order of words in string java 
Java :: print jtable in java 
Java :: System.Windows.Interactivity 
Java :: sort array from certain index java 
Java :: bigint is built in object 
Java :: create and populate list one line java 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =