Switch on String in tJava

One Star

Switch on String in tJava

Hello,
While using the tJava component we have an error when switching on a String:
Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
Cannot switch on a value of type String. Only convertible int values or enum constants are permitted

Talend is however configured to use a Java 7 JRE:

How is that possible ?
Kind regards,
Ivan.
Community Manager

Re: Switch on String in tJava

Hi 
It is a compilation error, can you show us the Java code on tJava component?
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Switch on String in tJava

Hi,
Here is the code.
I can't seem to add a screenshot though. It shows on my upload list and the editor but not in the final post.
switch (input_row.TYPE) {
case "A" :
context.table = "a";
break;
case "B" :
context.table = "b";
break;
case "C" :
context.table = "b";
break;
case "D" :
context.table = "c";
break;
case "E" :
context.table = "d";
break;
default :
throw new IllegalArgumentException("Unknown truncate action !");
}

And the error message :
Starting job a at 09:53 23/01/2015.
connecting to socket on port 3837
connected
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Cannot switch on a value of type String. Only convertible int values or enum constants are permitted
at a.b.c.tFileInputDelimited_1Process(c.java:589)
at a.b.c.runJobInTOS(c.java:914)
at a.b.c.main(c.java:757)
Job a ended at 09:53 23/01/2015.


Kind regards,
Ivan.
Community Manager

Re: Switch on String in tJava

Hi 
It is a basic Java issue, you can't use string type in switch statement expression with your JDK version, see 
http://stackoverflow.com/questions/6231907/java-7-switch-statement-with-strings-not-working
http://stackoverflow.com/questions/338206/why-cant-i-switch-on-a-string
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business

What’s New for Talend Spring ’19

Join us live for a sneak peek!

Sign up now

Tutorial

Introduction to Talend Open Studio for Data Integration.

Watch

Downloads and Trials

Test drive Talend's enterprise products.

Downloads

Definitive Guide to Data Integration

Practical steps to developing your data integration strategy.

Download