Solved

class keyword

Posted on 2002-07-19
1
236 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.

705 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