Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JAVA Boolean.toString()重写_Java_Boolean_Tostring - Fatal编程技术网

JAVA Boolean.toString()重写

JAVA Boolean.toString()重写,java,boolean,tostring,Java,Boolean,Tostring,我有方法printB(): 我还有课 public class ChangeBooleanValue { public static void main(String[] args) { // Add code printB(); } private static final void printB () { System.out.println(Boolean.TRUE); Sys

我有方法
printB()

我还有课

public class ChangeBooleanValue {
    public static void main(String[] args) {
        // Add code
        printB();      
    }


    private static final void printB () {
        System.out.println(Boolean.TRUE);     
        System.out.println(Boolean.FALSE); 
    } 
}
我想编写代码而不是读取
//添加代码
,这样输出将是:

true 
true


我知道通过一些Java技巧可以使用它。

您可以执行以下操作:

System.out.println(true);
System.out.println(true);
System.exit(0);
您也可以对
false
执行相同的操作


完整代码如下所示:

public class ChangeBooleanValue {
    public static void main(String[] args) {
        System.out.println(true);  // <--
        System.out.println(true);  // <--
        System.exit(0);            // <--
        printB();      
    }


    private static final void printB() {
        System.out.println(Boolean.TRUE);     
        System.out.println(Boolean.FALSE); 
    } 
}
公共类ChangeBooleanValue{
公共静态void main(字符串[]args){

System.out.println(true);//您可以执行以下操作:

System.out.println(true);
System.out.println(true);
System.exit(0);
您也可以对
false
执行相同的操作


完整代码如下所示:

public class ChangeBooleanValue {
    public static void main(String[] args) {
        System.out.println(true);  // <--
        System.out.println(true);  // <--
        System.exit(0);            // <--
        printB();      
    }


    private static final void printB() {
        System.out.println(Boolean.TRUE);     
        System.out.println(Boolean.FALSE); 
    } 
}
公共类ChangeBooleanValue{
公共静态void main(字符串[]args){

System.out.println(true);//您可以使用反射来更改
Boolean.true=Boolean.FALSE
或反之亦然。这并不是说有合理的理由这样做


另一种方法是编译您自己版本的布尔类,并使用它来做任何您想做的事情,同样也不是完全正常的。

您可以使用反射来更改
Boolean.TRUE=Boolean.FALSE
或反之亦然。这并不是说有合理的理由这样做


另一种方法是编译自己版本的Boolean类,并使用它来做任何你想做的事情,同样一点也不正常。

使用反射删除最后的修饰符,并将Boolean.FALSE替换为true

在这个回答中描述:


使用反射删除最终修改器并将Boolean.FALSE替换为true

在这个回答中描述:

代码来自:

输出:

true
true
代码来自:

输出:

true
true

不确定你到底想达到什么目标。这是家庭作业问题吗?你尝试过什么吗?你的标题回答了你的问题。什么是“糟糕透顶的井”?@pstanton你真的不想知道;)@arshajii你要对一个注定要失败的问题做多少次编辑;)不确定你到底想达到什么目的。这是家庭作业问题吗?你试过什么了吗?你的标题回答了你的问题。“烂井”是什么?@pstanton你真的不想知道;)@arshajii对于一个注定要失败的问题,你要费心编辑多少次;)或者
System.out.println(!true);
;)任务是:“不要更改编写的代码。添加但不要更改编写的代码”@G.Ch.这不会改变已经编写的任何内容,它只是
addcode
注释的替代品(如您所要求的)。此代码生成的输出如下所示:true false我想添加将生成输出的代码,其中将写入两个相同的值。不是三个,不是一个。@G.Ch.将此复制并粘贴到您已写入的
add code
;输出将是
true
(在单独的行上)。或
System.out.println(!true)
;)任务是:“不要更改已编写的代码。添加但不要更改已编写的代码”@G.Ch。这不会更改已编写的任何内容,它只是替换
添加代码
注释(如您所要求的)。此代码生成的输出如下所示:true false我想添加将生成输出的代码,其中将写入两个相同的值。不是三个,不是一个。@G.Ch.将此复制并粘贴到您已写入的
添加代码
;输出将为
true
(在单独的行上)。无法为最终变量赋值。无法为最终变量赋值
true
true