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

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Steven Simpson <ss@domain.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: methodhandle invoke with arguments cast error
Date Sat, 07 Feb 2015 18:25:37 +0000
Organization A noiseless patient Spider
Lines 34
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>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 8bit
Injection-Info mx02.eternal-september.org; posting-host="8418829f0c37f1486357e21dd5aac233"; logging-data="10350"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18GVFIy0nLXSPwvtD4RodrSdJQCzMmAleE="
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0
In-Reply-To <mb1k5j$2cf8$1@ariadne.rz.tu-clausthal.de>
Cancel-Lock sha1:h6+k+efgjgZhJY6ku2TYE8L9Tc8=
Xref csiph.com comp.lang.java.programmer:31073

Show key headers only | 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