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 division int by 0 
Java :: open youtube by default in full screen pragmatically 
Java :: illegal expression 
Java :: convert xml file to node tree with java 
Java :: convert text file into binnary format bitmap using java 
Java :: lighting strike solved 
Java :: print max activity by greedy technique in java 
Java :: convert kotlin to java online editor 
Java :: aaa testing java 
Java :: java format zero padded binary 
Java :: define 2d array in java 
Java :: executors java 
Java :: java optional parameters 
Java :: method in java 
Java :: java check if class is subclass 
Java :: java check if instance of subclass 
Java :: mp3 player java 
Java :: java compare char 
Java :: how to import borderlayout 
Java :: javafx initialize 
Java :: java string copy characters 
Java :: code wars jaden casting java 
Java :: ciclo for para percorere duas listas java 
Sql :: change nls_date_format 
Sql :: oracle get table schema 
Sql :: check connections to database postgres 
Sql :: get tables in database sql 
Sql :: string to int mysql 
Sql :: to date oracle with time 
Sql :: sql delete multiple ids 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =