Java sucks... But seriously

Pages: 123
I'm just trying to create an array of queues of strings. But no luck. It's something to do with Java generics I believe. I've tried:

1
2
3
ArrayBlockingQueue<String>[] arr = new ArrayBlockingQueue<String>[10](10)
ArrayBlockingQueue<String>[] arr = new ArrayBlockingQueue[10]
ArrayBlockingQueue<String>[10] arr = new ArrayBlockingQueue[10]


Not sure how to make it work :/

P.S.,
Why does Java have to have worlds longest names for everything?
ArrayBlockingQueue<String>[] arr = new ArrayBlockingQueue[10]
This should work. http://ideone.com/ms8lLd

Congratulations for accusing a language not doing what you'd like it to do, while you apparently put no effort into learning it.
Why put so much effort into a broken language? Just creating objects is so inconsistent and cumbersome. And generics are just a joke to use.

EDIT:
Thanks for the answer though, I appreciate it. I must have had something else earlier because it works just fine with that.
Last edited on
How inconsistent? Do you mean the above? I think it's pretty sensible, considering that with java generics Foo<Bar> and Foo<Baz> don't have different physical representations and that arrays don't have constructors.
Why put so much effort into a broken language? Just creating objects is so inconsistent and cumbersome. And generics are just a joke to use.
Why put so much effort into a broken language like C++? Pointers are so inconsistent and cumbersome. And templates are just a joke to use.

Nothing works when you try it for the first time. NEVER. I remember the good old times when I just started learning C++ and every program which had 100 lines or more just segfaulted. And later, I thought WinAPI was stupid with its LP(WC)STRs and everything. Now I'm learning Java and Android programming and again, everything looks stupid and complicated.
SomeClass<Type>[] arr = new SomeClass<Type>[10];
You tried every version but this one. The second "Type" in <> is optional in Java 7; you can use the diamond operator instead.

I'm also not seeing the inconsistency here, could you elaborate?

I do agree though about generics in Java being pretty poor, but as a language feature not introduced until 5 major versions into the language, you have to give it some slack.
Last edited on
SomeClass<Type>[] arr = new SomeClass<Type>[10];
You tried every version but this one. The second "Type" in <> is optional in Java 7; you can use the diamond operator instead.

This doesn't work in my java environment. It says,
cannot create a generic array of SomeClass<Type>

You should probably be using an ArrayList, or something like that; right?

Why does Java have to have worlds longest names for everything?

The naming conventions in java I actually like. Most of the time, you can guess what things are named using common sense. Things are named what they are.

What name would you us for an array backed blocking queue? I can't think of a better one.
Last edited on
Ah, yeah I always use ArrayList and I've never used arrays of generic types. I guess it makes sense that you don't specify the type after new because all the values are initialized to null and you have to specify the type when you create each one.

As for naming conventions, they're pretty reasonable, but really they need to invent a ReverseCamelCaseForwardAlpha sort so that the names are in a more logical order. Currently, List and ArrayList are on opposite sides of the world in an alphabetical class listing.

I do agree though that Java needs SOME kind of aliasing syntactic sugar.
Last edited on
closed account (1yR4jE8b)
Why does Java have to have worlds longest names for everything?


http://javadoc.bugaco.com/com/sun/java/swing/plaf/nimbus/InternalFrameInternalFrameTitlePaneInternalFrameTitlePaneMaximizeButtonPainter.html
I have nowhere near as much fun using java as I have c++ but I haven't had usfull results from c++ yet, however I never learnt to install sfml and only recently got c++11, Im going to spend £30 quid and get that c++11 book and started making loads of fun stuff, I really cant wait to escape what feels like blind mainstream following that is java

EDIT: I feel genuinley unoriginal for using it

Hey if you feel like helping me install a JSON library thing or explaining where to put (and not to put) a JSON jar, please give me ANY JSON advice you have on my JSON thread over their Im actually doing my first serious grown up work I actually feel quite clever and special
Last edited on
You should just install SDL, devonrevenge.
Last edited on by Fredbill30
yeah I did, it was fun too, just sfml has other fun bits and everyone talks about how simple and elegant it is.

more on topic: why do i have to write Boolean and Integer, and string has to be a capital, so many long words, even though you have a smart IDE JAVA is still a massive great big fat tart of a language
Last edited on
@devonrevege Java has 10 primitive types and a Class wrapper for 9 of them:
void -> java.lang.Void
boolean -> java.lang.Boolean
byte -> java.lang.Byte
char -> java.lang.Character
short -> java.lang.Short
int -> java.lang.Integer
long -> java.lang.Long
float -> java.lang.Float
double -> java.lang.Double
<references> -> N/A

You can't reference primitive types, which is why the wrapper classes exist. If you want to reference other references, you need a wrapper class for that too, because references are primitives and cannot be referenced by other references.
Why is Java frequently bought up in a C++ forum?
@Fredbill, because c++.com is a very good coding forum and java forums arnt as good as c++ forum asking java questions in the lounge.

@LB Oh yeah of course, I see now, I forget that Java is made out of C XD

EDIT: Speaking of java sucking im stuck on something and I dont want to start a new thread because I feel dumb for asking...

In my web hosting file manger thing can I send a java class file there, this class file will have an url, if i send data to that url, and that little class file is a program that expects things being sent to it some how, is THAT how I create a program that can be used like a data base on my website? cos im well stuck.
Last edited on
devonrevenge wrote:
@LB Oh yeah of course, I see now, I forget that Java is made out of C XD
I'm lost; how does that have to do with anything??
Well its a higher level language so I thought that when it was being made out of c...making something called int that wasnt the c int but the java int would have been confusing, and that all the libraries used to make all these bits where made outta c too so there would be conflicts when typing int...but i was just being stupid :/
You must be confused; people use the primitive types in Java all the time. That is, you often write just plain "int" in Java.
I keep doing that, im glad they will teach me as if I knew nothing at uni
Java does not have the longest names... Objective-C, my friend:

NSTextViewWillChangeNotifyingTextViewNotification

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSTextView_Class/Reference/Reference.html
Last edited on
Pages: 123