Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

referencing primitive types

Status
Not open for further replies.

carpeliam

Programmer
Mar 17, 2000
990
US
I have an object that has a &quot;getXXX&quot; method. In this code here, the <FONT FACE=monospace>key</font> variable holds &quot;XXX&quot; (for the purposes of this question). The return type for this is &quot;long&quot;. Not &quot;Long&quot;, but primitive &quot;long&quot;.<br><br>Depending on the type of <FONT FACE=monospace>c</font>, I want to fill the object using the &quot;setXXX&quot; method. To make sure my types agree, I check c's type through a series of if statements.<br><br>My question is, how do I check c against a primitive type? Or do I have to convert to a string and test it that way? Please tell me I can check the class itself without having an extra layer of conversion... :eek:)<br><br><FONT FACE=monospace>Class c = o.getClass().getMethod(&quot;get&quot; + key, null).getReturnType();<br>Class[] parameterFiller={c};<br>if (c == Long.class) {<br>&nbsp;&nbsp;&nbsp;&nbsp;Long[] valueHolder = {Long.valueOf(value)};<br>&nbsp;&nbsp;&nbsp;&nbsp;o.getClass().getMethod(&quot;set&quot;+key, parameterFiller).invoke(o, valueHolder);<br>} else if (c == String.class) {<br>&nbsp;&nbsp;&nbsp;&nbsp;String[] valueHolder = {value};<br>&nbsp;&nbsp;&nbsp;&nbsp;o.getClass().getMethod(&quot;set&quot;+key, parameterFiller).invoke(o, valueHolder);<br>}</font><br><br>the above code doesn't work, because c is not of type &quot;Long&quot;... so when it gets to &quot;if (c == Long.class)&quot;, that line gets skipped right over. How do I reference the primitive type?<br><br>thanks... <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence."
 
nevermind, I found the answer... <FONT FACE=monospace>Long.TYPE</font> refers to Long's primitive type. <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top