Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #31051 > unrolled thread
| Started by | Philipp Kraus <philipp.kraus@flashpixx.de> |
|---|---|
| First post | 2015-02-05 20:57 +0100 |
| Last post | 2015-02-06 14:31 +0100 |
| Articles | 8 — 3 participants |
Back to article view | Back to comp.lang.java.programmer
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
| From | Philipp Kraus <philipp.kraus@flashpixx.de> |
|---|---|
| Date | 2015-02-05 20:57 +0100 |
| Subject | methodhandle invoke with arguments cast error |
| Message-ID | <mb0hto$1vp8$1@ariadne.rz.tu-clausthal.de> |
Hello, 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? Thanks Phil
[toc] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2015-02-05 15:18 -0500 |
| Message-ID | <54d3d026$0$281$14726298@news.sunsite.dk> |
| In reply to | #31051 |
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?? Arne
[toc] | [prev] | [next] | [standalone]
| From | Philipp Kraus <philipp.kraus@flashpixx.de> |
|---|---|
| Date | 2015-02-06 06:41 +0100 |
| Message-ID | <mb1k5j$2cf8$1@ariadne.rz.tu-clausthal.de> |
| In reply to | #31052 |
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. In a hardcoded source I would do (int), but I must use a method handle because of other dependencies Phil
[toc] | [prev] | [next] | [standalone]
| From | Steven Simpson <ss@domain.invalid> |
|---|---|
| Date | 2015-02-07 18:25 +0000 |
| Message-ID | <1u1iqb-ihc.ln1@s.simpson148.btinternet.com> |
| In reply to | #31056 |
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
[toc] | [prev] | [next] | [standalone]
| From | Steven Simpson <ss@domain.invalid> |
|---|---|
| Date | 2015-02-05 21:55 +0000 |
| Message-ID | <9f5dqb-kk5.ln1@s.simpson148.btinternet.com> |
| In reply to | #31051 |
On 05/02/15 19:57, Philipp Kraus wrote: > MethodHandle h = getMethodHandle_with_unreflect What is getMethodHandle_with_unreflect, and where is the rest of the line? -- ss at comp dot lancs dot ac dot uk
[toc] | [prev] | [next] | [standalone]
| From | Philipp Kraus <philipp.kraus@flashpixx.de> |
|---|---|
| Date | 2015-02-06 06:43 +0100 |
| Message-ID | <mb1k8m$2cgp$1@ariadne.rz.tu-clausthal.de> |
| In reply to | #31054 |
On 2015-02-05 21:55:21 +0000, Steven Simpson said: > On 05/02/15 19:57, Philipp Kraus wrote: >> MethodHandle h = getMethodHandle_with_unreflect > > What is getMethodHandle_with_unreflect, and where is the rest of the line? I don't write the full code, I get the method handle from a method, that uses reflection API to get the method and returns with MethodHandles.lookup.unreflect the handle of the method. Phil
[toc] | [prev] | [next] | [standalone]
| From | Steven Simpson <ss@domain.invalid> |
|---|---|
| Date | 2015-02-06 11:32 +0000 |
| Message-ID | <cbleqb-ku4.ln1@s.simpson148.btinternet.com> |
| In reply to | #31057 |
On 06/02/15 05:43, Philipp Kraus wrote: > On 2015-02-05 21:55:21 +0000, Steven Simpson said: > >> On 05/02/15 19:57, Philipp Kraus wrote: >>> MethodHandle h = getMethodHandle_with_unreflect >> >> What is getMethodHandle_with_unreflect, and where is the rest of the >> line? > > I don't write the full code, [...] Ah, I didn't perceive it as pseudo-code. -- ss at comp dot lancs dot ac dot uk
[toc] | [prev] | [next] | [standalone]
| From | Philipp Kraus <philipp.kraus@flashpixx.de> |
|---|---|
| Date | 2015-02-06 14:31 +0100 |
| Message-ID | <mb2fm5$2i0r$1@ariadne.rz.tu-clausthal.de> |
| In reply to | #31059 |
On 2015-02-06 11:32:28 +0000, Steven Simpson said: > On 06/02/15 05:43, Philipp Kraus wrote: >> On 2015-02-05 21:55:21 +0000, Steven Simpson said: >> >>> On 05/02/15 19:57, Philipp Kraus wrote: >>>> MethodHandle h = getMethodHandle_with_unreflect >>> >>> What is getMethodHandle_with_unreflect, and where is the rest of the line? >> >> I don't write the full code, [...] > > Ah, I didn't perceive it as pseudo-code. yes, hope it is okay Thx
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web