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

  • Home
  • SEARCH
  • 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 1004171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:05:35+00:00 2026-05-16T08:05:35+00:00

Say I have a method declaration like: private void someMethod(final String someKey, final Object

  • 0

Say I have a method declaration like:

private void someMethod(final String someKey, final Object dataType){
  // Some code
}

I want to call it like:

someMethod("SomeKey", String);
someMethod("SomeKey", Date);

I can it do it in different ways like declaring an int with different values representing the type, an enum, or the like.

But can I just pass the type itself?

EDIT:

To elaborate, I can do like:

someMethod("SomeKey", 1); // 1 = String
someMethod("SomeKey", 2); // 2 = Date

This doesn’t look good.

  • 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-05-16T08:05:36+00:00Added an answer on May 16, 2026 at 8:05 am

    If you’re looking to pass the type of object as a parameter, you can do it by passing a java.lang.Class

    i.e.

    public void someMethod( String someKey, Class clazz ) {
        ... whatever
    }
    

    Is that what you’re looking for?

    edit: incorporating Mark’s comment.

    You can call this like

    someMethod( "keyA", Date.class );
    someMethod( "keyB", String.class );
    

    etc.

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

Sidebar

Related Questions

Say I have a method signature like this: protected override void Initialize(params object[] parameters)
Lets say I have a method which controls some character movement like the following:
Let's say you have some Java code as follows: public class Base{ public void
Let's say I have a subroutine/method that a user can call to test some
Let's say that I have a method that looks like this: def raise_if_client_status_error(xml_resp) #
Say I have the following function: bool foo (int a); // This method declaration
Say I have a method called GetCatsByColor which takes a color as a string,
Let's say we have the following method declaration: Public Function MyMethod(ByVal param1 As Integer,
Let's say you have the following code: string encoded=9,8,5,4,9; // Parse the encoded string
I have some code that uses multi-methods and would ideally like to overload the

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.