Results 21 to 27 of 27
- 01-09-2009, 10:59 AM #21
Member
- Join Date
- Dec 2008
- Location
- Italy
- Posts
- 79
- Rep Power
- 0
Yes, you're right. :D And this is NOT a special task, it's quite common and I can't figure out why they didn't redisign the signature to use generics. I think it wouldn't have been such a difficult thing. Anyway Java 1.5 has been around for 3 years, so I think it is not a new thing... And generics are only a compile-time feature, so the code is perfectly backwords compatible (this is what I know, but if you have more informatin :) ...)
Originally Posted by fishtoprecords
Above all Nithya (the original author of this post) is a STUDENT. And I think that introducing features like autoboxing or casting between Objs and prims to him is very premature and could confuse him.
I think that casts are generally a bad thing and you should avoid it. In this case (and lots of other cases) there is no need to cast, so there is no need to defend them
- 01-09-2009, 05:55 PM #22
- 01-09-2009, 06:56 PM #23
Member
- Join Date
- Dec 2008
- Location
- Italy
- Posts
- 79
- Rep Power
- 0
Yes backward compatibility is an important issue but I mean, for example:
Is it possible using generics? I can only use generic code but actually I have never written generic types or methods...//This is pseudo-code... I don't know if it even compiles...
public class Object<T> {
...
public boolean equals(? extends T);
...
}
Generic methods
They have rewritten the Class class (which now is Class<T>, and Comparable etc...) without breaking back-comp, it seems... Do you have further info? Moreover this would be an important feature, because it makes no sense to test an Integer and a JButton for equality :p ...
- 01-10-2009, 05:36 PM #24
Hey, this looks like fun!
I remeber when I was sat at a piano by my grandmother. She told me in effect that all the ineffect ual intellecutals could correctly code all the code that could be coded, generic ( ally ) Pat can spell, I cannot. Can Cats dance? Who says Cats can't dance?
Generics may be good for Geriatrics, without knowing the code behind them, you get behind. Every time you try to get the code behind them, Dogs in Blind Alleys take you to the C-Way. In Java, there is no void anything anywhere, that's what Generics sounds like to me in practice. Instead of using Generics, why not get some editors that will show the code?
Without a full-blown codebase, the question "test and Integer and a JButton for equality" is an indeterminate.
Therefore appropriate for a razz, and I take your challenge:
One cannot back-comp on a codebase that is not even semi-portably consistent across all problem domains written to run on all platforms.
At some point, a 32/64 bit pointer gets ripped to a call into 16-bit single threaded runtime lib,....
The result is rampant downloads, choking the internet to it's knees.Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 02-05-2010, 04:51 AM #25
Member
- Join Date
- Feb 2010
- Posts
- 1
- Rep Power
- 0
Missing the question...
The original question was how to cast an array of objects to an array of scalars, more specifically Integer[] -> int[].
Integer[] objArr = ...
...
// create a new scalar int array the same size as the Integer array
int[] recs = new int[objArr.size()];
// copy the data from the Integer array to the int array
for (int idx=0; idx<objArr.length; idx++) {
recs[idx]=objArr[idx].intValue();
}
enjoy...
- 02-05-2010, 06:39 AM #26
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,545
- Rep Power
- 11
Although I risk reanimating this thread: why are you using .intValue()? As the very first answer asked, "Go through the Integer array and copy each element to the int array. Did you try that?"
The only time it will fail is if the original array contains a null element. And it should fail in that case.
- 02-11-2010, 05:41 PM #27
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Anyway this is a very old thread. :P OP didn't response for a long time.
Similar Threads
-
Integer to String
By zervine in forum Forum LobbyReplies: 3Last Post: 09-12-2008, 12:07 PM -
Integer length
By jithan in forum New To JavaReplies: 1Last Post: 06-12-2008, 03:35 PM -
How to convert integer to the hexadecimal and octal number
By Java Tip in forum java.langReplies: 0Last Post: 04-06-2008, 07:40 PM -
Breaking down an integer
By Emily in forum New To JavaReplies: 1Last Post: 03-06-2008, 06:39 PM -
Integer vs int
By bugger in forum New To JavaReplies: 1Last Post: 11-14-2007, 09:13 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks