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

2012/5/6

String in switch

erdelf erdelf

2012/5/6

#
Hello, I want to use a String in switch, but I get an error: strings in switch are not supported in -source 1.6 (use -source 7 or higher to enable strings in switch). I already updated to java 7 Any idea?
davmac davmac

2012/5/6

#
Greenfoot currently allows Java 6 syntax only, sorry.
danpost danpost

2012/5/7

#
@erdelf, you could concatenate the possible strings into one string (if needed, with divider characters) and use the 'indexOf' command to get an integer to 'switch' on.
erdelf erdelf

2012/5/7

#
Thx for help. I will think about it. When will Greenfoot be updated?
davmac davmac

2012/5/7

#
The problem is that if Greenfoot compiles with Java 7 compatibility on, people using Java 6 won't be able to run the scenarios. We'll probably change Greenfoot to compile for Java 7 only when Java 6 is not really being used anymore.
BardyL BardyL

2013/6/14

#
Well, one year later JDK 7 should have been deployed on many more computers. And for those who haven't upgrade, it would be a good motivation for it. Isn't it the right time to upgrade Greenfoot to Java 7 ? We shouldn't have to wait 5 years more unti JDK 6 has disappeared of the world... Let's go ahead ! It's boring not beeing able to use switch with String, especially with a learning tool for beginner...
ChaosNemisis ChaosNemisis

2013/8/1

#
BardyL wrote...
Well, one year later JDK 7 should have been deployed on many more computers. And for those who haven't upgrade, it would be a good motivation for it. Isn't it the right time to upgrade Greenfoot to Java 7 ? We shouldn't have to wait 5 years more unti JDK 6 has disappeared of the world... Let's go ahead ! It's boring not beeing able to use switch with String, especially with a learning tool for beginner...
Agreed wholeheartedly. Made an account just so I could say that. I ran into this problem just now. I guess I'll have to stick with the enum workaround. =(
Relicum Relicum

2013/8/2

#
ChaosNemisis wrote...
BardyL wrote...
Well, one year later JDK 7 should have been deployed on many more computers. And for those who haven't upgrade, it would be a good motivation for it. Isn't it the right time to upgrade Greenfoot to Java 7 ? We shouldn't have to wait 5 years more unti JDK 6 has disappeared of the world... Let's go ahead ! It's boring not beeing able to use switch with String, especially with a learning tool for beginner...
Agreed wholeheartedly. Made an account just so I could say that. I ran into this problem just now. I guess I'll have to stick with the enum workaround. =(
Sorry but it may be good for learning Switch statements with strings but in terms of resources it uses roughly 10 times the cpu as if you used an Int.
iau iau

2013/8/2

#
Last month, about 20% of Gallery users were on Java 6. So yes, it's still being used.
ChaosNemisis ChaosNemisis

2013/8/3

#
iau wrote...
Last month, about 20% of Gallery users were on Java 6. So yes, it's still being used.
And if Greenfoot switched, in a month 0% of Gallery users will be using Java 6. Maybe it does deserve a little more time to let people switch though. Maybe half a year. But really, there are few advantages to using Java 6. Though I would feel sorry for those unfortunate few who for various reasons are stuck using it.
Relicum wrote...
Sorry but it may be good for learning Switch statements with strings but in terms of resources it uses roughly 10 times the cpu as if you used an Int.
This is true, but I'd say a lot of Greenfoot users aren't making programs where this would matter. I did figure that in the long run it would be better to make my current project not do resource intensive things. I don't expect that it will ever be capable of lagging any computer though. =P
davmac davmac

2013/8/3

#
On Mac OS X, Java 7 is unfortunately still too buggy to be used reliably. The applet plugin in particular has problems which make a lot of Greenfoot scenarios unplayable. I hope that this will change, but in the meantime, switching to Java 7 would negatively affect a significant portion of our users. At some point Greenfoot will require and support Java 7, just not right now.
leuveg leuveg

2014/10/8

#
Hei, i use Greenfoot 2.4 at Linux with JDK 1.7 but the switch with Strings not working in greenfood. I get the errormessage
strings in switch are not supported in -source 1.6 (use -source 7 or higher to enable strings in switch)
Any chance that greenfoot in the upcoming release use java 7? cheers, L.
davmac davmac

2014/10/8

#
Hi, the next release will be a bug-fix release and will still support Java 6. The release after that will probably, at this stage, skip straight to Java 8.
leuveg leuveg

2014/10/9

#
Oh, sounds good. Than i hope my shool migrate from Windows XP to Win7 or 8 so we can use Java 8. ^_^ Greetings, L.
You need to login to post a reply.