• entries
455
639
• views
424517

# Reason to hate java #4789

113 views

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*

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

Jack

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...

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

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

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.

## Create an account

Register a new account