gpt4 book ai didi

java - "Can be package local"是什么意思? (IDEA 检查)

转载 作者:IT老高 更新时间:2023-10-28 20:29:27 24 4
gpt4 key购买 nike

我将 IntelliJ 用于“检查代码”,其结果之一是:

  问题概要     可以本地打包(在第 18 行(public class HeartBeat))

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

整个类(class)都是这样的:

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 可见性。

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

有关详细信息,请参阅 Controlling Access to Members of a Class .

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

关于java - "Can be package local"是什么意思? (IDEA 检查),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30678457/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com