Solved

class keyword

Posted on 2002-07-19
1
231 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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Receive file in Servlet 1 36
endX challenge 2 48
java set up 1 44
Modeling a class in java 5 31
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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
The viewer will learn how to implement Singleton Design Pattern in Java.

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now