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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:12:09+00:00 2026-06-06T04:12:09+00:00

I have a Java code where the return type of a function has unbounded

  • 0

I have a Java code where the return type of a function has unbounded wildcard type (?). How can I emulate something like this in C++? e.g.

    public GroupHandlerSetting<?> handleGroupProcessingFor(final EventHandler<T> eventHandler)
    {
        return new GroupHandlerSetting<T>(eventHandler, eventProcessors);
    }
  • 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-06T04:12:11+00:00Added an answer on June 6, 2026 at 4:12 am

    In C++ all type arguments must have a name, whether you use it or not, so there is no question mark. Just make it a template argument to the function and give it a name and you should be fine.

    template <typename T>
    struct templ {
       template <typename U>
       void assign( templ<U> & u );      // public void assign<?>( temple<U> u )      
    };
    

    That’s the trivial part, the more complex part is enforcing constraints on the type, and for that you can use SFINAE:

    template <typename T>
    struct templ {
       template <typename U, typename _ = std::enable_if< 
                                  typename std::is_base_of<U,T>::value
                                           >::type >
       void super( templ<U> & u );       // public void super_<? super T>( templ<?> u )
    
       template <typename U, typename _ = std::enable_if<
                                  typename std::is_base_of<T,U>::value 
                                           >::type >
       void extends( templ<U> & u );     // public void extends_<? extends T>( templ<?> u )
    }
    

    That is using C++11 for the SFINAE, in C++03, it is a bit more convoluted (as if this version was simple) as you cannot use SFINAE on a function template argument, so SFINAE needs to be applied to either the return type or extra function arguments. SFINAE is a much more powerful solution, it can be used not only to provide super and extends but with many other features of types or compile time values. Google for SFINAE and you will find many cases of SFINAE being used, many of them will be C++03 style.

    There was a proposal for concepts that would have greatly simplified the syntax, but no agreement was reached and in a move to push the standard to completion it was deferred for a later standard.

    Now, this is really not that common in C++ as it is in Java, so I recommend that you provide a different question with what you want to do, and you will get ideas for designs in more idiomatic C++.

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

Sidebar

Related Questions

I have a java code which gets the function names, their return types, their
i have this java code: ArrayList<MessageMap> ids = getNewMail(UserID, type, maxIdMessage); Message[] message =
I have java source code in a text file. There has to be entered
I have a json which is return from the java code. I use toJSON
I have implemented this function: static <X,Y> Y castOrNull(X obj) { try { return
currently we have this code to upload file <input id='fileBrowse' type='file' style=width:187px;height:20px class='fileBrowse' onchange=onBrowseFile(
I have Epic Editor which returns a handle to the window (see Java code
I have Java code and TeX documents in the same project. I use TeXlipse
I already have Java code to display and process data from a database. I
In my source tree have Java code which is automatically generated from XSD files.

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.