From e46c3b1ca566b15d4df793026e55893a73c417d2 Mon Sep 17 00:00:00 2001
From: simonbrandhof The JLS does not enforce the placement of package annotations. This placement may vary based on implementation. The JLS does highly recommend that all package annotations are placed in the package-info.java file. See Java Language specification, sections 7.4.1.1.
The correct way to do get an array of a specific type from a collection is to use c.toArray(new String[]);
or c.toArray(new String[c.size()]);
(the latter is slightly more efficient).
There is one common/known exception exception to this. The toArray() method of lists returned by Arrays.asList(...) will return a covariantly typed array. For example, Arrays.asArray(new String[] { "a" }).toArray()
will return a String []. FindBugs attempts to detect and suppress such cases, but may miss some.
When a B is constructed, the constructor for the A class is invoked before the constructor for B sets value. Thus, when the constructor for A invokes getValue, an uninitialized value is read for value.
]]>x == 0 || y == 0
).
]]>
putNextEntry()
and
closeEntry()
.]]>
putNextEntry()
and
closeEntry()
.]]>
If all clone() methods call super.clone(), then they are guaranteed to use Object.clone(), which always returns an object of the correct type.
]]>java.net.URI
instead.
(e.g., by using the isAnnotationPresent method).
.]]>
java.net.URI
instead.
hard or impossible for your code to be invoked by other code.
Consider throwing a RuntimeException instead.]]>
java.net.URI
instead.
or Runtime.runFinalizersOnExit for any reason: they are among the most
dangerous methods in the Java libraries. -- Joshua Bloch]]>
String
directly.]]>
String.toString()
is just a redundant operation.
Just use the String.]]>Boolean
objects instead.]]>
Integer
, Short
, Character
, and Byte
.
]]>
Double
and Float
.
]]>
versions instead.
]]>e2
is of type Float
, then e1
is unbox
converted to a floating point value, and boxed. See JLS Section 15.25.
]]>
new Double(d).intValue()
). Just perform direct primitive coercion (e.g., (int) d
).]]>Condition
interface.
]]>
Random.nextInt(n)
method.
]]>
r.nextInt(n)
, rather than using (int)(r.nextDouble() * n)
.
]]>
finalize()
method should have protected access,
not public.]]>finalize()
methods are useless, so they should
be deleted.]]>finalize()
method, making it
redundant. Delete it.]]>
super.finalize()
.]]>
boolean equals(Object)
method.
]]>
boolean equals(Object)
method.
]]>
java.lang.Object
, the parameter of equals()
must have type java.lang.Object
.]]>
Foo.class == o.getClass()
).
It is better to check if this.getClass() == o.getClass()
.
]]>
this
object. There might not be
this code, but it is worth reviewing.
]]>
hashCode
implementation to use is:
return 42; // any arbitrary constant will do
}]]>
equals()
method. Therefore, the class may
violate the invariant that equal objects must have equal hashcodes.]]>
hashCode
implementation to use is:
return 42; // any arbitrary constant will do
}]]>
hashCode
implementation to use is:
define the hashCode()
method
to throw UnsupportedOperationException
.]]>
hashCode
implementation to use is:
override hashCode()
. Therefore, the class may violate the
invariant that equal objects must have equal hashcodes.]]>
hashCode
implementation to use is:
java.lang.Object
, the parameter of equals()
must have type java.lang.Object
.]]>
String.intern()
method, the same string
value may be represented by two different String objects. Consider
using the equals(Object)
method instead.]]>
equals(Object)
method instead.]]>
equals(Object)
method instead.]]>
Comparable
interface, the parameter of compareTo()
must have type java.lang.Object
.]]>
Thread.start()
is the right method to call.]]>
NoSuchElementException
if is called when there are no more elements to return.]]>
Since there normally exist only two Boolean objects, this code could be synchronizing on the same object as other, unrelated code, leading to unresponsiveness and possible deadlock
]]>Foo
's from different packages.
]]>