Sep 28

java: enums and switch

In the wiki2wikiproject I am currently working on is a java-Enum called Wikitype:

public enum WikiType {
twiki,jspwiki
}

We all now the nice an sweet construct named switch..case. One would suggest it was quite easy to use this enum in a switch statement:

switch (mode) {
case WikiType.jspwiki:
return new JSPWikiSyntax();
case WikiType.twiki:
return new TWikiSyntax();
}

Seems right, but Java has kind of an own opinion about that:

The enum constant WikiType.twiki reference cannot be qualified in a case label

Odd. So we try to use the switch with a string. This tells us switch can only be used on integers and enums. Odd enough. A bit it clicking in eclipse leads us to the following code:

switch (mode) {
case (WikiType) WikiType.valueOf("jspwiki"):
return new JSPWikiSyntax();
case (WikiType) WikiType.valueOf("twiki"):
return new TWikiSyntax();
}

Still not working:

Type mismatch: cannot convert from WikiType to WikiType

The solution to this problem is actually quite simple, though a bit irrational. The case statements inherit the context of the switch argument object. So there is no need to fully qualify the cases.

switch (mode) {
case jspwiki:
return new JSPWikiSyntax();
case twiki:
return new TWikiSyntax();
}

Share

Posted in Uncategorized | Tagged
Sep 02

picasa and eos 400d raws

Picasa is quite a nice tool. Even though it works in linux only with an ugly wine-workaround it delivers quite a nice picture experience. However, there is quite an annoying drawback: it can't handle the raw image files of my eos 400d(Digital Rebel XTi). The CR2 raw files are split in four in picasa. Obviously those problems exist for a while now as I have found the earliest mentions of this dated back to September '06. Hopefully Google will correct this behaviour in the near future, because I'd rather keep my images in raw format than in jpegs.

Share