Java/TypeChecking
From charlesreid1
This gets complicated fast when you're using generic types.
Neal Grafter's blog has a page talking about reified generics. This has to do with casting objects to generic types, and casting to objects that utilize the diamond notation, like Collections objects.
This stack overflow question addresses some similar issues.
The approach that introduces the least amount of conflict is to use (Object o) as a parameter type, then cast to whatever type you need. If you must cast to a type that takes generic parameter types, like a Map or a Set, you can explicitly tell the complier not to complain by adding the decorator @SuppressWarnings("unchecked")
ahead of the method where the cast happens or ahead of the class definition of the type. See this stack overflow question for some additional information.
Computer Science notes on computer science topics on the wiki, for educational and learning purposes
Part of the 2017 CS Study Plan.
Python/Exceptions · Python/Assertions · Python/Decorators Python/Os (os module) · Python/Strings Python/Splat · Python/Iterators · Python/Generators Python/Comparators · Python/Lambdas
Builtin features of Java: Java/Exceptions · Java/Assertions · Java/Memory · Java/Interfaces Java/Generics · Java/Decorators · Java/Diamond Notation Java/Iterators · Java/Iterable · Iterators vs Iterable Java/Comparators · Java/Comparable · Comparators vs Comparable Java/Numeric · Java/TypeChecking · Java/Testing · Java/Timing · Java/Profiling Documentation: Javadocs · Java/Documentation Tools and functionality: Java/URLs · Java/CSV External libraries: Guava · Fastutil · Eclipse Collections OOP: OOP Checklist · Java/Abstract Class · Java/Encapsulation · Java/Generics
|
See also: