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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:03:29+00:00 2026-06-17T15:03:29+00:00

In this method I get string as input and according to the string name

  • 0

In this method I get string as input and according to the string name I need to return value sometimes its string sometime int ,double,int64 ,bool etc
Since its dynamic type i don’t know how to define it in the method return type
and how to add to it the value and how to call to this method that the return type is dynamic ,any idea?

public static ? SwitchInput(String TypeName) {

       if (TypeName == "java.lang.String" ) {
            Return = "A";
        }
        else if (TypeName == "int" ) {
            Return =  1;
        }
        else if (TypeName == "double") {
            Return = 1.00
        }

etc for bool and all the other types

    }
  • 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-17T15:03:31+00:00Added an answer on June 17, 2026 at 3:03 pm

    To know what the return type is, you have to find a container where all these types fit in. Obviously, this is Object. You’d have to convert the primitive types to the corresponding object (like int to Integer).

    A better approach would be to create a new container class, which holds a generic type <T>. Like

    public class SwitchDemo {
    
    public static SwitchInputType<?> switchInput(String typeName) {
        if (typeName.equals("java.lang.String")) {
            return new SwitchInputType<String>(new String("A"));
        } else if (typeName.equals("int")) {
            return new SwitchInputType<Integer>(new Integer(312));
        }
        return null;
    }
    
    public static class SwitchInputType<T> {
        private T type;
    
        public SwitchInputType(T type) {
            super();
            this.type = type;
        }
    
        public T getType() {
            return type;
        }
    
        public void setType(T type) {
            this.type = type;
        }
    }
    
    public static void main(String[] args) {
        SwitchInputType<?> sit1 = SwitchDemo.switchInput("java.lang.String");
        System.out.println(sit1.getType());
        SwitchInputType<?> sit2 = SwitchDemo.switchInput("int");
        System.out.println(sit2.getType());
    }
    

    }

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

Sidebar

Related Questions

Having a method like this: @GET @Path(/name/{name}) @Produces(MediaType.TEXT_PLAIN) public String getProperty(@PathParam(name) String name) {
My controller is like this @RequestMapping(value =/getTaggedProducts, method = RequestMethod.GET) @ResponseBody public String getProductsTagged(@RequestParam(questionnaireId)Long
Currently i have this method: static boolean checkDecimalPlaces(double d, int decimalPlaces){ if (d==0) return
To get all contacts I'm using ABAddressBookCopyArrayOfAllPeople method but, this method return all contacts
I have a spring bean that I get like this within a method- repAppCaller
I have this method to get a generic repository out of a dictionary: public
I am using this method to get a list of week start from my
I was trying to get clarification on this: Method-1: Dim request = CreateRequest(uri) //some
I have this code in a prepareForSegue method // Get destination view UIViewController *viewController
i use this method before 1 time. but Now i can not get video

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.