> > but what about referencing the method, does it
> affect
> > the reference?
>
> Huh?
>
I'm just wondering if a method has a final parameter like:
public void vo(final String h){..}
when referencing that method, does the variable inside have to be a constant String:
By making your parameter final, the following will not compile.
public void foo(final String s) {
s = "hello"; // error
}
What do you mean by "does the variable inside have to be a constant String"?
> By making your parameter final, the following will
> not compile.
> [code]
> public void foo(final String s) {
>s = "hello"; // error
> /code]
> What do you mean by "does the variable inside have to
> be a constant String"?
I was wondering if the method was referenced in another class, does the variable that goes into that method have to be a constant.
But I fgured it out, the variable doesn't have to be a constant
Message was edited by:
vopo
> > > but what about referencing the method, does it
> > affect
> > > the reference?
> >
> > Huh?
> >
> I'm just wondering if a method has a final parameter
> like:
> public void vo(final String h){..}
>
> when referencing that method, does the variable
> inside have to be a constant String:
No.
Final simply means that that parameter's value can't change. It has nothing to do with the caller's variable.
void foo(final Bar bar) {}
...
Bar bar = someBar;
foo(bar); // caller's bar is not final, but that's ok