473,785 Members | 2,309 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reflection passing arrays of primitives as argument

Hi All, I am trying to create a BeanHelper class which will set a beans
values from the request much the same as it would be form a jsp using
'usebean'.

I can get everything to work except for methods which take arrays of
primitives. If my bean method takes an array of primitves I get a
"java.lang.Ille galArgumentExce ption: argument type mismatch" when
method.invoke(b ean, args) is called ,where 'bean' is my bean to set & 'args'
is an array of Objects.

Here is a snippet from the code which creates an Object for the args array
which works with Objects & primitives

private static Object getArgument(Str ing parameter, Class paramType) {
Object returnObject = null;
if (paramType.equa ls(Boolean.clas s) ||
paramType.equal s(boolean.class )) {
System.out.prin tln("returning Boolean");
returnObject = new Boolean(paramet er);
}
return returnObject;
}

here's some code from the method which creates Object arrays if the bean
method takes an array. This works if the method argument takes Integer[],
but not if it takes int[].

private static Object[] getArrayArgumen t(String[] parameters, Class
paramType) {
Object[] returnObject = null;
if (paramType.equa ls(Integer[].class) ||
paramType.equal s(int[].class)) {
System.out.prin tln("returning Integer[]");
Integer[] intArray = new Integer[parameters.leng th];
for (int i = 0; i < parameters.leng th; i++) {
intArray[i] = new Integer(paramet ers[i]);
}
returnObject = intArray;
}
return returnObject;
}
Any help greatly appreciated :-)
--
-P
Jul 17 '05 #1
1 5437
Worked it out :-)
Object returnObject = null;
if (paramType.equa ls(int[].class)) {
System.out.prin tln("returning int[]");
int[] intArray = new int[parameters.leng th];
for (int i = 0; i < parameters.leng th; i++) {
intArray[i] = Integer.parseIn t(parameters[i]);
}
returnObject = intArray;
}
--
-P
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
4135
by: Mark | last post by:
hello! I have a class method that takes a variable number of parameters and correctly deals with them with func_get_args, etc ... i.e. class ABC { public function MooSaysTheCow()
5
12624
by: harry | last post by:
I have 2 multi-dim arrays double subTotals = null; String rowTitles = null; I want to pass them to a function that initialises & populates them like so - loadData( rowTitles, subTotals);
2
29599
by: aliensite | last post by:
I am trying to pass arrays of various lengths to a function. However the values are read as a string. What is the easiest way to pass the values? <script type="text/javascript"> <!-- function foo() { var args = "start "; for( var i=0 ; i < arguments.length; i++ ) { if(i==0)
1
3442
by: Kurt Richardson | last post by:
Hi all Sorry to bother you with what is probably a really trivial question for you C++ experts. My programming skill are pretty amateur, but I'm pretty good at VB.NET. However, I'm wanting to realise some of the speed benefits of writing some of my routines in C++ and accessing them from my VB software. I have managed to do this with a few simple routines in
3
3796
by: Mark | last post by:
Hi From what I understand, you can pass arrays from classic ASP to .NET using interop, but you have to change the type of the.NET parameter to object. This seems to be because classic ASP passes a variant containing an array, and interop expects a parameter of type object if you are passing a variant (you are expected to cast it to the correct type in your code). I'd like to find a way of passing arrays so that you don't need to change...
7
1834
by: Rik | last post by:
Hi, I have an Multithreaded application in VB.NET. I inherited a Sub Class and which define an Array variable of string in that Sub Class. Now I want to Carry that Sub Class Array back to the Calling Class?? without using Function Return. Can any one Help me in this regard.
1
2500
by: Eric Capps | last post by:
This may be more of a Java question, but I feel that JavaScript experts may be more qualified to help me find a solution. In short: is it possible to call a Java method from JavaScript, passing as an argument a JavaScript array (in my case, an array of doubles)? Supposing I have array x containing only doubles, I have tried: document.MyApplet.myMethod(x); But the method only ever seems to receive "null" as an argument.
4
2506
by: Christian Maier | last post by:
Hi After surfing a while I have still trouble with this array thing. I have the following function and recive a Segmentation fault, how must I code this right?? Thanks Christian Maier
1
4569
by: Fizzics | last post by:
This is my first post here at Bytes. I have been trolling it, mostly with the help of Google searches, for some time now. I have done about all of the searching and reading that I really know how to do, but because I can't seem to locate something that is even close... I am posting... I would like to thank this community, I have received a great deal of help already. Background: I have a pre-existing C code, that I have written, which works....
0
9646
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9484
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10350
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10097
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9957
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7505
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4055
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.