I'm having a really hard time using generics in Java. Why are they so damn confusing? Real generics aren't this hard. Can someone break this down and explain this to me?
Name:
Anonymous2007-01-25 4:04
>>1
Ah, yes. This is a problem of misconception. Java is a static language. You can't really do things such as generics in static programmings and expect it to be usable and nice.
What you really need is a dynamic language, one that is not anal and stupid about data types and allows you to reuse code. May I suggest Python? If you don't like Python, you can try Ruby. If you don't like Python nor Ruby, commit seppuku.
Name:
932007-01-25 4:09
>>1
What about it is presenting problems for you? If you haven't yet, take a quick read of the generics tutorial.
Generics you say? How original, and look how cute it is: List<Integer> myIntList = new LinkedList<Integer>();
And it's original, no one every thought about it before... *cough*c++templates*cough*
That's why I officially say to all my Java friends today: #include <list>
using std::list;
is ten years old, Java is just a clone.
Name:
Anonymous2007-01-25 15:57
>>6
JAva generics are quite a different animal than c++ templates. dont confuse them.
Name:
Anonymous2007-01-25 16:52
>>7
Indeed. In C++ you can write
template<class T> T* single(T a) {
T* l = new T[1];
l[0] = a;
return l;
}
but the equivalent Java code won't work, because Java is "type safe".
<T> T[] single(T a) {
T[] l = new T[1];
l[0] = a;
return l;
}
Name:
Anonymous2007-01-25 17:42
>>7
different where? List<int> (in Java) and list<int> (in C++)? wow, that's different.
If you're just doing generic data structures, they're basically the same. However, that's all Java can do. C++ templates can do much, much more as they provide a general way to write "code that writes code" through metaprogramming.
>>12
I have never seen ONE single example that proves that, the only thing I have seen is something the smug Lisp weenies masturbate furiously over: reimplementing loops...
Name:
Anonymous2007-01-26 11:25
>>13
LISP macros seem to help securing your job position: there's no LISP. There's your LISP, his LISP, that guy's LISP, and all are different, so LISP is made for single-man projects. It makes single men be as productive as several, but it can't grow past that. Getting to work on a non-trivial LISP project means you need to learn a new language, and all the stuff you use may not work.
Name:
Anonymous2007-01-26 12:52
>>14
I heard there's some file in your home directory that true Lisp hackers fill with their personal macros that they then use in production code, is that so?
Name:
Anonymous2007-01-26 12:57
>>13 >>14 >>15
LOL java fags talking about lisp.
hahaha.
>>14 Getting to work on a non-trivial LISP project means you need to learn a new language, and all the stuff you use may not work.
In practice, that doesn't happen. When you follow the widely-accepted BEST PRACTICES OF COMMON LISP MACRO WRITING, you end up with a small set of useful macros that extend the language in non-surprising ways (as in, not fucking up things around them, not polluting the namespace with random crap).
Sure, it's possible to make strange magic happen in unexpected places, but why would you want that? It would be like one of those IOCCC entries that #defines everything to mean something totally different.
1. Java generics are somewhat limited but they are slowly walking towards C# generics which are more permissive.
2. Type safety is considered a good thing by Java/C# programmers.
3. You cannot instantiate a generic type with int (List<int>) because int is a value type, or whatever you want to call it, you need to use the int wrapper class Integer. Wrapper classes or type boxing is not done automatically as it is in C# (this might be a good thing, since it has a cost and at least forces programmers to face potential efficiency issues).
Name:
Anonymous2011-12-31 15:31
>>26
>(this might be a good thing, since it has a cost and at least forces programmers to face potential efficiency issues)
It's going to be removed in the next edition obviously, programming these days means not thinking
Name:
Anonymous2011-12-31 17:07
>>27
Really now? I won't have to write EatShitAndDie<Integer> anymore then?
this is so cool. I'm jelly that you got to use lisp in a professional setting.
anyways yall, common lisp has plenty of features in it that will let you easily do anything you could in java, given that you are willing to learn lisp and leverage its features, and also read lisp code.
>>43
Listen you hourly worker, Java generics can hold more than references to an object. This can be demonstrated in a few lines of Java code. To say that generics only hold references to an object demonstrates the person has no clue as to what they are talking about.
Now you don't you shut the fuck up and write some code that shows what I'm talking about instead of jerking off on shit you pretend to know, but really don't.
Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy