什么是“可以打包本地”意思? (IDEA检查) [英] What does "Can be package local" mean? (IDEA Inspection)

查看:192
本文介绍了什么是“可以打包本地”意思? (IDEA检查)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用IntelliJ作为Inspect Code,其中一个结果是:

I used IntelliJ for "Inspect Code", and one of its results is:

问题概要可以是本地包(第18行 (公共类HeartBeat)

  Problem synopsis      Can be package local (at line 18(public class HeartBeat))

这是什么意思,我该如何解决?

What does it mean, how can I fix it?

整个班级是这样的:

package com.xxxxxxxxxxx.app.xxxx;

public class HeartBeat
{
    private static final Logger LOG = LoggerFactory.getLogger( HeartBeat.class );
    private final File heartBeatFile;


    public HeartBeat( File heartBeatFile )
    {
        this.heartBeatFile = heartBeatFile;
    }


    public void beat()
    {
        try
        {
            FileUtils.writeStringToFile( heartBeatFile, String.valueOf( System.currentTimeMillis() ) );
        }
        catch( IOException e )
        {
            LOG.error( "Error while writing heart beat log", e );
        }
    }
}


推荐答案

IDEA指的是 package-private 可见性。

IDEA is referring to package-private visibility.


可以使用修饰符声明一个类 public ,在这种情况下,该类对所有类都可见。如果一个类没有修饰符(默认,也称为包私有),它只在自己的包中可见

A class may be declared with the modifier public, in which case that class is visible to all classes everywhere. If a class has no modifier (the default, also known as package-private), it is visible only within its own package

For有关详细信息,请参阅控制对班级成员的访问

For more information, see Controlling Access to Members of a Class.

您可以通过从类中删除 public 关键字来解决问题(如果该类不打算在包外使用),或者通过使用来自不同包的类。

You can solve the problem by removing public keyword from the class (if the class is not intended to be used outside the package), or by using the class from a different package.

这篇关于什么是“可以打包本地”意思? (IDEA检查)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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