This site requires JavaScript, please enable it in your browser!
Greenfoot back
PiRocks
PiRocks wrote ...

2011/3/14

Java final syntax

PiRocks PiRocks

2011/3/14

#
I am making an applet (though not in Greenfoot because it uses Java3D) and I can't figure out how to make a final variable. I know in applets you shouldn't use the constructor (use init instead) but eclipse won't let me assign my final variable in the init() method.
davmac davmac

2011/3/15

#
As always: post your code... :)
JL235 JL235

2011/3/15

#
You can only assign final class fields outside of a method or constructor (when you declare the field) or in the constructor. Although yes you should use 'init' for applets, the fact is you cannot set your final field there. However the applets constructor should still be called anyway, so you can still set your final variable there.
You need to login to post a reply.