I created a unit test :
new Callable() {
@Override
public Object call() throws
.....
I have received warning in Eclipse:
Callable is a raw type. References to generic type Callable<V>
should be parameterized
Should I write code like:
new Callable<Object>()
for eliminating warning, or not? It seems only junit test and there is no sense to add additional code... Thanks.
The generic collections should be used whenever possible instead of classes such as ArrayList in the System. Collections namespace. You can create your own generic interfaces, classes, methods, events, and delegates. Generic classes may be constrained to enable access to methods on particular data types.
Generics enable the use of stronger type-checking, the elimination of casts, and the ability to develop generic algorithms. Without generics, many of the features that we use in Java today would not be possible.
By using generics, programmers can implement generic algorithms that work on collections of different types, can be customized, and are type safe and easier to read.
According to oracle documentation, the following points are the disadvantage of generics: Cannot instantiate Generic types with primitive types. Cannot create instances of type parameters. Cannot declare static fields whose types are type parameters.
Yes, it's a good practice to avoid raw types and use generic types. Using Callable<Object>
makes it clear that the Callable is intended to return any kind of Object. Using Callable
doesn't make that clear.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With