Solved

class keyword

Posted on 2002-07-19
1
234 Views
Last Modified: 2010-08-05
What is the keyword "class" doing in this statement?

InputStream stream = IconCache.class.getResourceAsStream(path);

this is from the method:
private Image createStockImage(Display display,
                               String path)
{
  try
  {
   InputStream stream = IconCache.class.getResourceAsStream(path);
   if (stream != null)
   {
     ImageData imageData = new ImageData(stream);
     if (imageData != null)
     {
       ImageData mask = imageData.getTransparencyMask();
       return new Image(display, imageData, mask);
     }
  }
  } catch (Exception e) {
  }
return null;
}

which is from IconCache.java, part of the FileViewer example in the Eclipse SWT
0
Comment
Question by:jdaues
1 Comment
 
LVL 3

Accepted Solution

by:
gandalf94305 earned 50 total points
ID: 7165951
For any class X, X.class is the respective class object. Try String.class.getName(). The getResourceAsStream is a method defined in java.lang.Class (see below).

Cheers,
--gandalf.

java.lang.Class getResourceAsStream

public InputStream getResourceAsStream(String name)

    Finds a resource with a given name. This method returns null if no resource with this name is found. The rules for searching resources associated with a given class are implemented by the defining class loader of the class.

This method delegates the call to its class loader, after making these changes to the resource name: if the resource name starts with "/", it is unchanged; otherwise, the package name is prepended to the resource name after converting "." to "/". If this object was loaded by the bootstrap loader, the call is delegated to ClassLoader.getSystemResourceAsStream.

Parameters: name - name of the desired resource
Returns: a java.io.InputStream object.
Since: JDK1.1
See Also: ClassLoader
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question