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 8041061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:05:37+00:00 2026-06-05T04:05:37+00:00

How to reduce this usiong reflection private static Object determineDataType(final String value, String dataType)

  • 0

How to reduce this usiong reflection

private static Object determineDataType(final String value, String dataType)
{
    System.out.println("Name--->>" + dataType);
    if(dataType.equals(Boolean.class.getName()))
    {
       return new Boolean(value);
    }
    else if(dataType.equals(String.class.getName()))
    {
        return new String(value);
    }
    else if(dataType.equals(Character.class.getName()))
    {
        return new String(value);
    }
    else if(dataType.equals(Byte.class.getName()))
    {
        return new Byte(value);
    }
    else if(dataType.equals(Short.class.getName()))
    {
        return new Short(value);
    }
    else if(dataType.equals(Integer.class.getName()))
    {
        return new Integer(value);
    }
    else if(dataType.equals(Long.class.getName()))
    {
        return new Long(value);
    }
    else if(dataType.equals(Float.class.getName()))
    {
        return  new Float(value);
    }
    else if(dataType.equals(Double.class.getName()))
    {
        return  new Double(value);
    }
    //defualt return the String value, Lets' AOPI do the Validation
    return new String(value);
}
  • 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-05T04:05:39+00:00Added an answer on June 5, 2026 at 4:05 am

    You can use Class.forName and method getConstructor (here is an example):

    Object instance = Class.forName(dataType)
             .getConstructor(new Class[] {String.class})
             .newInstance(new Object[]{value});
    

    By the way it will not work for Character and Boolean because you make a special treatment for them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used this function to convert string to bits. def a2bits(chars): return bin(reduce(lambda
I need to reduce this boolean expression to its simplest form. Its given that
I recently encountered with this question: How to reduce this expression: s>73?61:60; . The
How it is possible to reduce this record? <xsl:template match=BR> <br/> </xsl:template> <xsl:template match=B>
I have this reduce function: protected void reduce(Text key, Iterable<SortedMapWritable> values, Context context) throws
This should reduce the executable size quite a bit in some of my very
Is there any way to combine all of this to reduce the amount of
Does anyone knows why after I apply this algorithm in c++ to reduce the
Is there a way to dynamically create an object using a string as the
Imagine I have this object (written with Ruby literals) stored in a MongoDB: {tags

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.