Stephen Upton

Greenhorn
+ Follow
since Dec 26, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Stephen Upton

Thanks Henry! That helps on the second part. I have your book on Java Threads, which helps with the first part. I'm now curious as to best practices or ideas on figuring out whether it's best just to start a new jvm or start a thread for my compute task (the one I'm using the jvm or thread for).

thanks!
steve
16 years ago
Hi all,

I'm looking for any good reference material on programming in java on multi-core machines. I'm looking for ways to query the number of cores on a machine, so that I may then tailor the number of threads I generate or alternatively, just starting different jvm's, since the threads/jvm will be independent jobs. Any hints on best practice on this would be welcome as well.

thanks!
steve
16 years ago
Hi Roger,

You cannot cast an array to another array as there is no hierarchy amongst arrays. You can only cast an array to Object.



I think you hit the nail on the head! After some reflection (pun intended), I realized I was trying to shortcut calling a number of methods using the varargs, but now realize there should still be only one method match.

Thank y'all for your help!
steve
p.s. I LOVE JavaRanch!
16 years ago
Hi Jim,

actionParameters is a String[]. If I don't cast to Object[], I get a warning from Eclipse, and if ignore the warning, I still get the same exception.

Oh, well on to change the code to something else that works or to try an experiment on something simple...
16 years ago
Hi Jim,

Thanks! I'll work on keeping the topics in the same thread. ;-)

Actually, the problem is more complicated than I posted. I don't know what class A is. I was actually trying to call different methods with differing number of parameters (all Strings, though), so I think I found a way around that complication. However, here's the code I'm actually working with that throws a IllegalAccessArgument (error below) (actionParameters is a String[]):



and here's the error it throws on the invoke line:



Thank you all for your help.
steve
16 years ago
Previously, I received an answer on this (see thread topic without the part 2), where I was struggling to find the correct syntax to invoke a method that had a variable argument list using reflection, e.g.,



and I wanted to use reflection to call this method (since I won't know the method name until runtime).

The previous answer was this:


However, I'm still struggling with how to invoke this. I've tried:


I get an warning saying I need to cast the ss to Object[], but then when I do that, I get a ClassCastException when the m.invoke is executed.

Hope that explains enough.
thanks!
steve upton
17 years ago
Thanks for the welcome - and the answer!
17 years ago
Hi,

I'm struggling to find the right syntax to invoke a method using reflection that uses variable argument list, e.g.,


then


hope that's clear
thank you
steve
17 years ago