不使用该字段的值 [英] value of the field is not used

查看:149
本文介绍了不使用该字段的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在私有int count = 0之前在eclipse上收到了上述警告;

这是我的代码:

package synchronise;

public class Mysync {

    private  int count=0;

    public Mysync() {
        // TODO Auto-generated constructor stub
    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Mysync sync = new Mysync();
        sync.dowork();

    }

    public void dowork(){

        Thread mysync = new Thread(new Runnable() {

            public void run() {
                // TODO Auto-generated method stub

                for(int i=0; i<2000; i++){
                    // System.out.println()

                    count++;
                }


            }
        });

        Thread mysync2 = new Thread(new Runnable() {

            public void run() {
                // TODO Auto-generated method stub

                for(int i=0; i<2000; i++){
                    // System.out.println()

                    count++;
                }


            }
        });
        mysync.start();
        mysync2.start();

        try {
            mysync.join();
            mysync.join();
            } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}

我该如何解决这个问题?为什么我收到此错误?我更新了代码。

How can I fix this? Why am I getting this error? I updated the code.

推荐答案

如果要修复警告,只需使用它即可。

If you want to fix the warning, just use it.

例如。

System.out.println(count);

警告将消失。

警告表示在编译代码时,优化可能会删除无用的代码。

The warning indicates when compile the code, the optimization may delete the useless code.

此处无用的代码表示它具有与输出无关,因为软件都是关于输入
和输出。

Here useless code means it has nothing to do with the output, since software is all about input and output.

这篇关于不使用该字段的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆