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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:59:42+00:00 2026-05-26T05:59:42+00:00

I have a Java method something like this public boolean ReadBool(String ValueName, Boolean Value)

  • 0

I have a Java method something like this

public boolean ReadBool(String ValueName, Boolean Value)  
{  
  boolean Retval = ...;  
  ...  
  Value = true;  
  ...  
  return bRetval;  
}

that I call from native code (C++) like this:

jMethodID MethodId = pEnv->GetMethodID(ClassId, "ReadBool", "(Ljava/lang/String;Ljava/lang/Boolean;)Z");  
// What goes instead of "??" ?  
bool bOk = pEnv->CallBooleanMethod(myobject, MethodId, pEnv->NewStringUTF("Value1"), "??");

My intention is for the Java method to “return” a boolean value in Value. I understand that a built-in boolean will not work for this purpose. Is it possible to do this with a Boolean wrapper? How does one construct the object to pass in place of “??” ?

I have googled around, but some questions remain. For example, I suppose I could pass an object created by calling Boolean’s <init> “method”. But wouldn’t the assignment in the Java ReadBool make Value refer to a newly created wrapper, throwing away that first object? In that case I would have called <init> for nothing. I think it should be possible to create (in the native code) something that Java sees as an object that is null and whose type is Boolean. Is that possible? Or am I on the wrong track altogether?

  • 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-26T05:59:44+00:00Added an answer on May 26, 2026 at 5:59 am

    Booleans are immutable in Java, so you need your own wrapper class, which can be really simple though:

    public class BooleanWrapper {
        public boolean val;
        // public is fine here imo, but you can obviously use [g|s]etters as well
    }
    

    Or if you don’t want this, we can use a.. well not really pretty, but nice to know hack:

    public void hack(boolean[] vals) {
        vals[0] = true; // voila, now you change the value itself
    }
    

    Has some obvious drawbacks when calling (and looks strange), but if you’re fine with keeping a specific parameter sequence, you can do:

    public void hack(boolean.. vals) {
        vals[0] = true; // voila, now you change the value itself
    }
    

    that way the caller doesn’t have to use stuff like new boolean[] {};

    You can obviously cheat and change the internal state of the Boolean object itself, but that will have unwanted consequences (booleans are cached ergo if you change the Boolean.TRUE instance to false internally this will give interesting results). So don’t do that.

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

Sidebar

Related Questions

When I have a method like this: public static void foo(String param) throws IOException
I have something like this: public abstract class Menu { public Menu() { init();
When I compile something like this: public class MyClass { void myMethod(String name, String
I have a Java method that takes 3 parameters, and I'd like it to
I have code that looks like this: public class Polynomial { List<Term> term =
Right now I'm going to have to write a method that looks like this:
I want something like this: public abstract class ListenerEx<LISTENER, PARENT> implements LISTENER { PARENT
I have a method called public int getSize() and it is suppose to return
I have a Parent class. import java.util.HashMap; import java.util.Map; public class Parent { Map<String,String>
I have a Java method which starts up a Process with ProcessBuilder, and pipes

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.