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

2012/8/25

setBackground in World

SPower SPower

2012/8/25

#
Hi all, I've got a little question, why is the method setBackground in World a final method? Thanks for the answers :)
SPower SPower

2012/8/27

#
Does nobody know?
kiarocks kiarocks

2012/8/28

#
It isn't. I just had a look at the API. EDIT: It might be so that you don't override it in your world subclass and mess it up.
danpost danpost

2012/8/28

#
@kiarocks, in the summary of methods, it does not show as such; but, in the method descriptions, it does show 'public final void setBackground(...)' for both. I could be wrong, but, I doubt that the word 'final' should be there at all. What are you finalizing? 'void'?
danpost danpost

2012/8/28

#
@kiarocks, even if you override it, you can still use 'super'.
kiarocks kiarocks

2012/8/28

#
No, if you look at the java specification for final, it it used in a method to prevent overrides of that particular method. (see this )
danpost danpost

2012/8/28

#
@kiarocks, I tried looking for something like that within the Java site, but was unable to locate it there. I was not aware of this functionality of 'final'. Thanks for the info.
kiarocks kiarocks

2012/8/28

#
I guess its mainly an API sort of thing, to prevent problems.
SPower SPower

2012/8/28

#
But if the setBackground method in World is final, why is the setImage method in Actor not final? Can sombody from the greenfoot team reply?
nccb nccb

2012/8/28

#
I'm not sure there is a particular reason that setBackground is final while other methods are not. A quirk of history.
davmac davmac

2012/8/28

#
I think, strictly speaking, they should both be final. The reason is that they are not intended to be overridden. They are called internally by Greenfoot and if they did not behave properly then they could cause Greenfoot itself to malfunction.
SPower SPower

2012/8/28

#
@davmac thanks for the info
You need to login to post a reply.