Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #31073

Re: methodhandle invoke with arguments cast error

From Steven Simpson <ss@domain.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: methodhandle invoke with arguments cast error
Date 2015-02-07 18:25 +0000
Organization A noiseless patient Spider
Message-ID <1u1iqb-ihc.ln1@s.simpson148.btinternet.com> (permalink)
References <mb0hto$1vp8$1@ariadne.rz.tu-clausthal.de> <54d3d026$0$281$14726298@news.sunsite.dk> <mb1k5j$2cf8$1@ariadne.rz.tu-clausthal.de>

Show all headers | View raw


On 06/02/15 05:41, Philipp Kraus wrote:
> On 2015-02-05 20:18:37 +0000, Arne Vajhøj said:
>
>> On 2/5/2015 2:57 PM, Philipp Kraus wrote:
>>> I use a method handle with this code:
>>>
>>> List<Object> args = new LinkedList();
>>> args.add( my object );
>>> args.add( new Double(5) );
>>>
>>> MethodHandle h = getMethodHandle_with_unreflect
>>> h.invokedWithArguments( args );
>>>
>>> The method, which is called shows
>>>
>>> public void doit( Integer x )
>>>
>>> so I get a cast error: Cannot cast java.lang.Double to 
>>> java.lang.Integer
>>> How can I do an explicit cast on the invokeMethodWithArguments?
>>
>> Stuff an Integer into the args List??
>
> Sorry, I forgot the information, that the list will be build 
> dynamically, so into the list can be pushed any numeric typ.

Is the method handle available when building the list?  You could get 
its MethodType, and scan over the parameter types for boxed primitives.  
If the corresponding argument is of type Number, call the appropriate 
XXXValue() method and push the result into the list.

-- 
ss at comp dot lancs dot ac dot uk

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

methodhandle invoke with arguments cast error Philipp Kraus <philipp.kraus@flashpixx.de> - 2015-02-05 20:57 +0100
  Re: methodhandle invoke with arguments cast error Arne Vajhøj <arne@vajhoej.dk> - 2015-02-05 15:18 -0500
    Re: methodhandle invoke with arguments cast error Philipp Kraus <philipp.kraus@flashpixx.de> - 2015-02-06 06:41 +0100
      Re: methodhandle invoke with arguments cast error Steven Simpson <ss@domain.invalid> - 2015-02-07 18:25 +0000
  Re: methodhandle invoke with arguments cast error Steven Simpson <ss@domain.invalid> - 2015-02-05 21:55 +0000
    Re: methodhandle invoke with arguments cast error Philipp Kraus <philipp.kraus@flashpixx.de> - 2015-02-06 06:43 +0100
      Re: methodhandle invoke with arguments cast error Steven Simpson <ss@domain.invalid> - 2015-02-06 11:32 +0000
        Re: methodhandle invoke with arguments cast error Philipp Kraus <philipp.kraus@flashpixx.de> - 2015-02-06 14:31 +0100

csiph-web