automatic boxing / unboxing ?

T

Tomba

Hi,

I'm working with Java 5.0 and somehow I can't figure out what the
problem is here:

Executing the following code:
try {
setter.invoke(bean, new Object[] { value });
} catch (IllegalArgumentException ex) {
System.out.println("Setter: " + setter + "\nArgument: " +
value.getClass().toString());
ex.printStackTrace();
}

I get the following output:

Setter: public void util.Transformation.setRelative(boolean)
Argument: class java.lang.Boolean
java.lang.IllegalArgumentException: object is not an instance of
declaring class ...

The function defenately exists but the problem seems to be the
conversion with Boolean and boolean. Shouldn't Java actually make it
work by unboxing the Boolean to the primitive boolean?
Hope you can see what I'm missing here... :/

Thank you!
 
V

VisionSet

try {
setter.invoke(bean, new Object[] { value });
} catch (IllegalArgumentException ex) {
System.out.println("Setter: " + setter + "\nArgument: " +
value.getClass().toString());
ex.printStackTrace();
}

Setter: public void util.Transformation.setRelative(boolean)
Argument: class java.lang.Boolean
java.lang.IllegalArgumentException: object is not an instance of
declaring class ...

It looks to me that the problem lies in not providing the correct arguments
to the invoke method, this is what is throwing the exception. Without the
code for invoke() it is not possible to know, but I guess invoke is
expecting different objects in the Object[]
 
T

Thomas Hawtin

VisionSet said:
try {
setter.invoke(bean, new Object[] { value });
} catch (IllegalArgumentException ex) {
System.out.println("Setter: " + setter + "\nArgument: " +
value.getClass().toString());
ex.printStackTrace();
}

Setter: public void util.Transformation.setRelative(boolean)
Argument: class java.lang.Boolean
java.lang.IllegalArgumentException: object is not an instance of
declaring class ...


It looks to me that the problem lies in not providing the correct arguments
to the invoke method, this is what is throwing the exception. Without the
code for invoke() it is not possible to know, but I guess invoke is
expecting different objects in the Object[]

Or bean is not a util.Transformation.

Tom Hawtin
 
T

Tomba

Thomas said:
VisionSet said:
try {
setter.invoke(bean, new Object[] { value });
} catch (IllegalArgumentException ex) {
System.out.println("Setter: " + setter + "\nArgument: " +
value.getClass().toString());
ex.printStackTrace();
}

Setter: public void util.Transformation.setRelative(boolean)
Argument: class java.lang.Boolean
java.lang.IllegalArgumentException: object is not an instance of
declaring class ...



It looks to me that the problem lies in not providing the correct
arguments
to the invoke method, this is what is throwing the exception. Without the
code for invoke() it is not possible to know, but I guess invoke is
expecting different objects in the Object[]


Or bean is not a util.Transformation.

Tom Hawtin

Tested with some more output, and indeed bean is not a Transformation.
Made an error there. Thanks Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top