Class GenericsExamples
java.lang.Object
net.jrodolfo.java_evolution.java05.GenericsExamples
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classLanguage-level feature used by the wildcard example.static interfaceFirst capability required by the multiple-bound example.static classPlatform-level feature used by the wildcard example.static interfaceSecond capability required by the multiple-bound example.static classConcrete type that satisfies both bounds.static interfaceBase type for the bounded wildcard example. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondescribePrioritizedFeature(T feature) Describes a value whose type parameter has multiple bounds.<T> TReturns the first element from a typed list without a cast.firstRawValue(List rawValues) Shows the old raw-list shape that generics were designed to replace.inttotalImportance(Iterable<? extends GenericsExamples.ReleaseFeature> features) Reads feature importance from any iterable producer ofGenericsExamples.ReleaseFeaturevalues or subtypes.typedNames(List<String> names) Creates a typed list of names.
-
Constructor Details
-
GenericsExamples
public GenericsExamples()
-
-
Method Details
-
typedNames
-
first
Returns the first element from a typed list without a cast.- Type Parameters:
T- the list element type- Parameters:
values- values to inspect- Returns:
- the first value
-
firstRawValue
-
totalImportance
Reads feature importance from any iterable producer ofGenericsExamples.ReleaseFeaturevalues or subtypes.The
? extends ReleaseFeaturewildcard says this method only reads feature values. That makes the API flexible: callers can passIterable<LanguageFeature>orIterable<PlatformFeature>without copying those values into a less specific collection first.- Parameters:
features- features to inspect- Returns:
- total importance score
-
describePrioritizedFeature
public <T extends GenericsExamples.NamedFeature & GenericsExamples.PrioritizedFeature> String describePrioritizedFeature(T feature) Describes a value whose type parameter has multiple bounds.<T extends NamedFeature & PrioritizedFeature>is a multiple-bound type parameter. It lets the method require both capabilities without inventing a separate combined interface. This is one place where Java exposes an intersection-type-style constraint in normal source code.- Type Parameters:
T- type that satisfies both bounds- Parameters:
feature- feature that has both a name and a priority- Returns:
- human-readable feature description
-