raw-types

Can unchecked warnings be avoided when overriding a method with raw type parameters?

I am extending a class defined in a library which I cannot change: public class Parent { public void init(Map properties) { ... } } If I am defining a class 'Child' that extends Parent and I am using Java 6 with generics, what is the best way to override the init method without getting unchecked warnings? public class Child exten...

Is it good practice to replace Class with Class<? extends Object> to avoid warnings?

In a bunch o' places in my code, I have something like this: public Class mySpecialMethod() { return MySpecialClass.class; } which causes the warning Class is a raw type. References to generic type Class should be parameterized. But, if I replace Class with Class<? extends Object> the warning goes away. Is this ...

What is a raw type and why shouldn't we use it?

Questions: What are raw types in Java, and why do I often hear that they shouldn't be used in new code? What is the alternative if we can't use raw types, and how is it better? Similar questions Should Java Raw Types be Deprecated? ...

Scala class cant override compare method from Java Interface which extends java.util.comparator

Hello All I'm currently working on a port of a jEdit plugin to write all code in Scala. However Im forced at a certain point to implement my own Comparator. My simplified code is as follows: class compare extends MiscUtilities.Compare { def compare(obj1: AnyRef, obj2: AnyRef): Int = 1 } The MiscUtilities.Compare has the following ...

What are the security implications of using raw types in Java?

I'm currently reviewing the security implications of various warnings in a large Java EE application. Since most of the code is several years old, it contains many uses of the raw collection types: List items = new List(); rather than the parametrized collection types: List<Item> items = new List<Item>(); The only security implicat...

Java 6: Unsupported @SuppressWarnings("rawtypes") warning

I moved to a new machine which has the latest Sun's Java compiler and noticed some warnings in the existing Java 6 code. The Eclipse IDE, suggested that I annotate the assignment with: @SuppressWarnings("rawtypes") For example: class Foo<T> { ... } ... @SuppressWarnings("rawtypes") Foo foo = new Foo(); When I moved back to the mach...

Name for a specific raw type/unchecked cast combo in Java generics usage

Effective Java 2nd Edition says that we should not use raw types in new code, and we must also try to eliminate all unchecked casts warnings, and to prove and document its safety if we choose to suppress such a warning. However, I've repeatedly seen a particular usage that combines raw types and unchecked casts in a type-safe manner. In...