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...