English 中文(简体)
改变java的班级功能中的生物价值
原标题:Changing boolean value in class function in java
  • 时间:2012-04-15 12:23:55
  •  标签:
  • java

我们能够改变 j的班级功能中的“蓝色”价值,正如这一变化是当地发挥作用一样。 我们如何能够使以下变化变数反映不采用这种方法?

public void changeboolean(Boolean b)
{
        if( somecondition )
        {
                b=true;
        }
        else
        {
                b=false;
        }
}

EDIT The code could be like this:

public String changeboolean(Boolean b,int show)
{
        if( somecondition )
        {
                b=true;
                show=1;
                return "verify again";
        }
        else
        {
                b=false;
                show=2;
                return "Logout";
        }
        show=3;
        return verifed;

}

I m searching for something like this

b.setvalue(true);

是否可能?

最佳回答

我们能够改变java的班级职能中的“ Boo”价值

No, Boolean is immutable, as all the summarypers for the primitive categories.

备选办法:

  • Return a boolean from your method (best choice)
  • Create a mutable equivalent of Boolean which allows you to set the embedded value. You would then need to modify the value within the instance that the parameter refers to - changing the value of the parameter to refer to a different instance wouldn t help you, because arguments are always passed by value in Java. That value is either a primitive value or a reference, but it s still passed by value. Changing the value of a parameter never changes the caller s variable.
  • Use a boolean[] with a single element as the wrapper type
  • Use AtomicBoolean as the wrapper type
问题回答

Boolean is immutable, like all the wrappers for the primitive types. Soln: Trying using MutableBoolean of apacheCommon http://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/mutable/MutableBoolean.html





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签