Reason to hate java #4789

posted in Not dead...
Published January 07, 2006
Advertisement
Quote:
Note: Some input files use unchecked or unsafe operations.


public BugReport getBugReport(int inPos) {			if(inPos < bugReports.size()) {		return (BugReport)bugReports.elementAt(inPos);		}	return null;}


yes, I know, I told it todo them... so give me a safe option... oh, wait, you cant.

*misses templates*

Previous Entry Assembly for the masses!
Next Entry Stuff..
0 likes 4 comments

Comments

jollyjeffers
Damn my Java must be getting rusty. What's wrong with that code?

Jack
January 07, 2006 01:52 PM
_the_phantom_
technically, nowt, the vector object "bugReports" stores everything as an object, so to get it back to the BugReport object you have to cast it.. the compile complains that this is unchecked/possibly unsafe...
January 07, 2006 02:14 PM
jollyjeffers
Ah, okay... that whole casting thing becomes so normal in Java that I failed to see anything wrong [lol]

I've not used the "Java 5" series - IBM were on Java 1.4.2 (i think) which was where I last did any serious Java programming. Is that warning some sort of by product of how they have their generics thing? I don't remember the 1.4.2 compiler ever complaining about that sort of thing.

Jack
January 07, 2006 04:41 PM
mldaalder
You should check out java 1.5, it has generics.

Though, I prefer templates (C++ templates), I don't care about having multiple copies of basicly the same thing but with class T replaced with double or char, as long as I don't have to do it.;P

Your code would become:

public BugReport getBugReport(int inPos) {
		
	if(inPos < bugReports.size()) {
		return bugReports.elementAt(inPos);	
	}
	return (BugReport)null;
}

:P

But your declaration of bugReports would be: vector<BugReport> bugReports.
January 07, 2006 05:11 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement

Latest Entries

Advertisement