A generic interface example. : Generic « Language Basics « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » Language Basics » GenericScreenshots 
A generic interface example.
A generic interface example.

interface MinMax<T extends Comparable<T>> 
  T min()
  T max()

 
class MyClass<T extends Comparable<T>> implements MinMax<T> 
  T[] vals; 
 
  MyClass(T[] o) { vals = o; 
 
  public T min() { 
    T v = vals[0]
    for(int i=1; i < vals.length; i++
      if(vals[i].compareTo(v0v = vals[i]
 
    return v; 
  
 
  public T max() { 
    T v = vals[0]
 
    for(int i=1; i < vals.length; i++
      if(vals[i].compareTo(v0v = vals[i]
 
    return v; 
  

 
public class GenIFDemo 
  public static void main(String args[]) { 
    Integer inums[] {3628}
    Character chs[] {'b''r''p''w' }
 
    MyClass<Integer> iob = new MyClass<Integer>(inums)
    MyClass<Character> cob = new MyClass<Character>(chs)
 
    System.out.println("Max value in inums: " + iob.max())
    System.out.println("Min value in inums: " + iob.min())
 
    System.out.println("Max value in chs: " + cob.max())
    System.out.println("Min value in chs: " + cob.min())
  
}


           
       
Related examples in the same category
1. A simple generic class. A simple generic class.
2. Demonstrate the non generic classDemonstrate the non generic class
3. A simple generic class with two type parameters: T and V.A simple generic class with two type parameters: T and V.
4. Java generic: Hierarchy argumentJava generic: Hierarchy argument
5. Java generic: Use a wildcard.Java generic: Use a wildcard.
6. Java generic: Bounded Wildcard argumentsJava generic: Bounded Wildcard arguments
7. Demonstrate a simple generic method.Demonstrate a simple generic method.
8. Use a generic constructor. Use a generic constructor.
9. Generic ArrayListGeneric ArrayList
10. Generic Data Structure
11. Boxing Generic Example
12. Unchecked Example
13. Interface Generic (Has compile error)
14. Generic StackGeneric Stack
15. Enum and GenericEnum and Generic
16. Generic HashMapGeneric HashMap
17. Foreach and generic data structureForeach and generic data structure
18. Stats attempts (unsuccessfully) to create a generic class
19. Java generic: Ambiguity caused by erasure on overloaded methods.
20. Java 1.5 (5.0) new feature: collection and thread
21. Demonstrate a raw generic type. Demonstrate a raw generic type.
22. A simple generic class heirarchy.A simple generic class heirarchy.
23. A nongeneric class can be the superclass of a generic subclass.A nongeneric class can be the superclass of a generic subclass.
24. Use the instanceof operator with a generic class hierarchy. Use the instanceof operator with a generic class hierarchy.
25. Overriding a generic method in a generic class. Overriding a generic method in a generic class.
26. Pre generics example that uses a collection.Pre generics example that uses a collection.
27. Data structure and collections: Modern, generics version.Data structure and collections: Modern, generics version.
28. Java hierarchy generic classJava hierarchy generic class
29. Java generic: A situation that creates a bridge method.Java generic: A situation that creates a bridge method.
30. Java generic: Generics and arrays.
31. Collections and Data structure: the generic wayCollections and Data structure: the generic way
32. Custom Generic Object TesterCustom Generic Object Tester
w___w__w___._j__a___v__a___2_s_._c__om_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.