Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.StackTraceElement;
fred rosenberger wrote:This is not the right approach.
You're idea of using parallel arrays to store these values is not an easy one to maintain. If a copy of "Saw" is lost, it gets tricky on how you delete it, and deleting the last one is much trickier than deleting the 4th from last one.
The idea in OOP is that you try to model the real world with your Classes. Think about a DVD. It would have a title, a price, and perhaps an Inventory Control (IC) number. These become your class variables. A given DVD has no idea if there is another copy of it.
Bruce Lentz wrote:
Hope this helps.
Thanks for the help cowboy. I never thought to write the code like this.
Matthew Brown wrote:Java has some optimisations built in for handling strings - read up on the "string pool" if you're interested. s = "foo" will try to avoid creating a new object if it isn't necessary (if a "foo" String exists in the pool it's safe to reuse it because Strings are immutable). Whereas s = new String("foo") will always create a new String.
Bruce Lentz wrote:This is actually my second go-around trying to submit this sample to the employer, the first time they told me it could have been implemented better using advanced algorithms (???). I guess I can't help but feel like there is a better way to get this task done.
Ivan Jozsef Balazs wrote:Actually no "rogue" pieces of executable code are possible.
You can have (unnamed) initializing blocks and assignments but nothing much more.
Anu satya wrote:String is immutable. So,
if you say
both a and b points to same foo" in the memory.
Olivier Legat wrote:
Matthew Brown wrote:Java has some optimisations built in for handling strings - read up on the "string pool" if you're interested. s = "foo" will try to avoid creating a new object if it isn't necessary (if a "foo" String exists in the pool it's safe to reuse it because Strings are immutable). Whereas s = new String("foo") will always create a new String.
Turns out you're right (and so was I)... I ran my program again and now it outputs "s1 == s2 :: true"I don't know why it outputted false the first time.
William P O'Sullivan wrote:What's your point?
That seems very excessive. Are you loading the 3D max app or models?