Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9175719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:57:50+00:00 2026-06-17T16:57:50+00:00

Possible Duplicate: Switch Statement with Strings in Java Im using the following code and

  • 0

Possible Duplicate:
Switch Statement with Strings in Java

Im using the following code and I wonder if there is a way to do it with switch ,
the reason that I don’t use it as default since type name is type string.(I know that this option is supported in 1.7 version but I need to use 1.6)
There is a way to overcome this problem ?

public static SwitchInputType<?> switchInput(String typeName) {

        if (typeName.equals("Binary")) {
            return new SwitchInputType<Byte>(new Byte("23ABFF"));
        }
        else if (typeName.equals("Decimal")) {
            return new SwitchInputType<BigDecimal>(new BigDecimal("A"));
        }
        else if (typeName.equals("Boolean")) {
            return new SwitchInputType<Boolean>(new Boolean("true"));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:57:51+00:00Added an answer on June 17, 2026 at 4:57 pm

    As explained in other answers, you can’t use switch statement with strings if you’re working with Java 1.6.

    The best thing to do is to use an enumerator instead of string values:

    public static SwitchInputType<?> switchInput(InputType type) {
        switch(type){
            BINARY:
                return new SwitchInputType<Byte>(new Byte("23ABFF"));
            DECIMAL:
                return new SwitchInputType<BigDecimal>(new BigDecimal("A"));
            BOOLEAN:
                return new SwitchInputType<Boolean>(new Boolean("true"));
        }
    }
    

    where:

    public enum InputType{
        BINARY, DECIMAL, BOOLEAN // etc.
    }
    

    UPDATE:

    In your Field class add an InputType fieldType property. Then inside the loop:

    MemberTypeRouting.switchInput(field.getFieldType());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Switch statement fallthrough in C#? The following code is illegal in C#
Possible Duplicate: Switch Statement with Strings in Java I am trying to use switch
Possible Duplicate: Switch Statement with Strings in Java Ok, basically i want to know
Possible Duplicate: Switch Statement With Strings in Java? Does the switch statement in Java
Possible Duplicate: Code before the first ‘case’ in a switch-statement I have the following
Possible Duplicate: ‘break’ statement when using curly braces in switch-case While merging a package
Possible Duplicate: Java: If vs. Switch For all the conditional statements that are observed
Possible Duplicate: Is it safe to assume strict comparison in a Javascript switch statement?
Possible Duplicate: Why can't variables be declared in a switch statement? How can a
Possible Duplicate: C# - Is there a better alternative than this to ‘switch on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.