4 ms·
A good contrast to make between Java and other languages on over-typing is Java's lack of a way to return multiple items at a time without making a container cl
by aston 19y ago
A good contrast to make between Java and other languages on over-typing is Java's lack of a way to return multiple items at a time without making a container class.
- Tichy 19y agoHow do other languages do it? I can't actually imagine it, odd as it sounds? You don't mean returning maps, I presume?
- Xichekolas 19y agodef return_three_values "1,2,3".split(',') end a, b, c = return_three_values Like that? (For the love of god, how do I get that in a pre tag?)
- bayareaguy 19y agoIf you indent something a little, it will look like this as you would expect from a <pre> tag
- Xichekolas 19y agoAhhh, I tried that, but apparently it doesn't work if you do it on the first line. So here it is, not on the first line. def return_three_values "1,2,3".split(',') end a, b, c = return_three_values
- deleted 19y ago[deleted]
- Tichy 19y agoThat's just returning an array, though, which Java could also do. What Java can't do is to assign variables to array values as in your example.
- aston 19y agoSo, yes, the lack of assignment is part of the problem. But, of course, the duck-typing is half the fun of something like that. I can return anything (of any type) I want in a tuple of any size just by comma delimiting. Java arrays aren't that flexible, and worse, if you use one that holds more than one type (say Integers and Floats), you have to cast them to Object before you drop them in, and you get to cast on the way back out. Lots of type-related overhead to simulate something that should be easy.
- Tichy 19y agoAgreed, the inflexible arrays are quite annoying, maybe THE most annoying aspect of Java.