The transient
keyword in Java is used to indicate that a field should not be part of the serialization (which means saved, like to a file) process.
From the Java Language Specification, Java SE 7 Edition, Section 8.3.1.3. transient
Fields:
Variables may be marked transient
to
indicate that they are not part of the
persistent state of an object.
For example, you may have fields that are derived from other fields, and should only be done so programmatically, rather than having the state be persisted via serialization.
Here's a GalleryImage
class which contains an image and a thumbnail derived from the image:
class GalleryImage implements Serializable
{
private Image image;
private transient Image thumbnailImage;
private void generateThumbnail()
{
// Generate thumbnail.
}
private void readObject(ObjectInputStream inputStream)
throws IOException, ClassNotFoundException
{
inputStream.defaultReadObject();
generateThumbnail();
}
}
In this example, the thumbnailImage
is a thumbnail image that is generated by invoking the generateThumbnail
method.
The thumbnailImage
field is marked as transient
, so only the original image
is serialized rather than persisting both the original image and the thumbnail image. This means that less storage would be needed to save the serialized object. (Of course, this may or may not be desirable depending on the requirements of the system -- this is just an example.)
At the time of deserialization, the readObject
method is called to perform any operations necessary to restore the state of the object back to the state at which the serialization occurred. Here, the thumbnail needs to be generated, so the readObject
method is overridden so that the thumbnail will be generated by calling the generateThumbnail
method.
For additional information, the article Discover the secrets of the Java Serialization API (which was originally available on the Sun Developer Network) has a section which discusses the use of and presents a scenario where the transient
keyword is used to prevent serialization of certain fields.
? extends HasWord
means "A class/interface that extends HasWord
." In other words, HasWord
itself or any of its children... basically anything that would work with instanceof HasWord
plus null
.
In more technical terms, ? extends HasWord
is a bounded wildcard, covered in Item 31 of Effective Java 3rd Edition, starting on page 139. The same chapter from the 2nd Edition is available online as a PDF; the part on bounded wildcards is Item 28 starting on page 134.
Update: PDF link was updated since Oracle removed it a while back. It now points to the copy hosted by the Queen Mary University of London's School of Electronic Engineering and Computer Science.
Update 2: Lets go into a bit more detail as to why you'd want to use wildcards.
If you declare a method whose signature expect you to pass in List<HasWord>
, then the only thing you can pass in is a List<HasWord>
.
However, if said signature was List<? extends HasWord>
then you could pass in a List<ChildOfHasWord>
instead.
Note that there is a subtle difference between List<? extends HasWord>
and List<? super HasWord>
. As Joshua Bloch put it: PECS = producer-extends, consumer-super.
What this means is that if you are passing in a collection that your method pulls data out from (i.e. the collection is producing elements for your method to use), you should use extends
. If you're passing in a collection that your method adds data to (i.e. the collection is consuming elements your method creates), it should use super
.
This may sound confusing. However, you can see it in List
's sort
command (which is just a shortcut to the two-arg version of Collections.sort). Instead of taking a Comparator<T>
, it actually takes a Comparator<? super T>
. In this case, the Comparator is consuming the elements of the List
in order to reorder the List itself.
Best Answer
It means the class is not yet added to the repository.
If your project was checked-out (most probably a CVS project) and you added a new class file, it will have the ? icon.
For other CVS Label Decorations, check http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.platform.doc.user/reference/ref-cvs-decorations.htm