Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
I read some articles written on "ClassCastException" but I couldn't get a good idea on that. Can someone direct me to a good article or explain it briefly.
I have mostly used generics to make type safe collections.What are the other uses of generics?
EDIT: Solved, see below Hi, In Java, I got an object that could be of any class. BUT - that object will always have to implement an interface, so when I call methods defined by the interface, that object will contain that method. Now, when you try to call a custom method on a generic object in Java, it mucks about typing. How can I somehow tell the compiler that my object does implement that...
Just trying to understand the behavior of java.lang.Object class. public class TypeCheck{ static void printMethod(Object obj) { System.out.println(obj); } public static void main(String[] args) { Object obj = new Object(); Integer intObj = new Integer(12); String stringObj = new String("Hello"); printMethod(obj); //---> j...
I have two very simple classes, one extends the other: public class LocationType implements Parcelable { protected int locid = -1; protected String desc = ""; protected String dir = ""; protected double lat = -1000; protected double lng = -1000; public LocationType() {} public int getLocid() { return locid; } public void setLocid(int val...
How can I cast an Object to an int in java?
Following oo situation: class A{ public A(){ System.out.println("Regular constructor of A"); } public A(int i){ System.out.println("Constructor of A with " + i); } } class B extends A{ public B(){ super(3); System.out.println("Regular constructor of B"); } public B(int i){ System.out.println("Constructor of B with " + i);...
Normally whats the reason to get java.lang.ClassCastException ..? I get the following error in my application java.lang.ClassCastException: [Lcom.rsa.authagent.authapi.realmstat.AUTHw
I'm using dynamic table layout, in that there is image, and textview. The data is coming from an XML document. What I want is that in table the layout at runtime, I have to get the parsed image and textview. I am getting the textview correctly but not the image. I used the method LoadImageFromWebOperations for loading the image, but it gets a class cast exception and error like this: org.apach...
How I can convert an Object to Array of Boolean Arrays? Boolean[][] mass; mass = (Boolean[5][5])Object;
Another way to ask the same question is, given 2 classes A and B, is it synonymous to say: "Object A can be cast into B" and "Object A is a descendant of B"? Thanks, JDelage Edit: Clarified the question to make it clearer that both A and B are classes.
The instructions say: Create an equals method that takes an object reference and returns true if the given object equals this object. * Hint: You'll need 'instanceof' and cast to a (Position) I have: class Position { private double x,y; private int id; public boolean instanceOf(Object a) { boolean isInstance; if ((Position)a instanceof Position) isIn...
 /*
  * Copyright 1994-1997 Sun Microsystems, Inc.  All Rights Reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Sun designates this
  * particular file as subject to the "Classpath" exception as provided
  * by Sun in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 */
package java.lang;

Thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an instance. For example, the following code generates a ClassCastException:

     Object x = new Integer(0);
     System.out.println((String)x);
 

Author(s):
unascribed
Since:
JDK1.0
public
class ClassCastException extends RuntimeException {
    
Constructs a ClassCastException with no detail message.
    public ClassCastException() {
        super();
    }

    
Constructs a ClassCastException with the specified detail message.

Parameters:
s the detail message.
    public ClassCastException(String s) {
        super(s);
    }
New to GrepCode? Check out our FAQ X