Solved

class keyword

Posted on 2002-07-19
1
235 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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 theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

734 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