• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Generic type MinMax

 
Ranch Hand
Posts: 664
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would like to create a generic type minmax, that generates the minmax depending on the type represented by <T>.



If you have better examples which help me understand the real use of generics in business, I would appreciate information, links, tutorials, and, source code.

Related links
1. Generics Tutorial (2004)
2. Java Generics FAQ, written by Angelika Langer (2010)
 
Saloon Keeper
Posts: 15510
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't, unless you know things about type T (for instance, whatever T is, the set of all unique T must be well-ordered and have an upper bound). So T must at least extend some interface that will provide this information. And if this interface provides this information, why would you need a generic class that does nothing but delegate to the methods defined in this interface?
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's assume you want to do this as an exercise. I suggest you take a look at java.util.Collections and its min and max methods, and what their generic types are.
(Note: the "Object &" part can be omitted since every single type matches that.)
reply
    Bookmark Topic Watch Topic
  • New Topic