java - 实现接口时出现错误“无法降低继承方法的可见性”
问题描述
我刚刚安装了 ta4j 技术分析库。它有一个名为 的接口类TimeSeries
。当我尝试在TimeSeries
String getName()
我收到以下错误:
无法从 TimeSeries 实施 org.ta4jcore.Timeserios.GetName 中减少一个真诚的方法的可见性
我的代码
import org.ta4j.core.*;
public class cMyChartVal implements TimeSeries {
/**
* @return the name of the series
*/
String getName()
{
return "TestSet";
}
.....
.....
}
TimeSeries
接口类
package org.ta4j.core;
import java.io.Serializable;
import java.time.format.DateTimeFormatter;
import java.util.List;
/**
* Sequence of {@link Bar bars} separated by a predefined period (e.g. 15 minutes, 1 day, etc.)
* </p>
* Notably, a {@link TimeSeries time series} can be:
* <ul>
* <li>the base of {@link Indicator indicator} calculations
* <li>constrained between begin and end indexes (e.g. for some backtesting cases)
* <li>limited to a fixed number of bars (e.g. for actual trading)
* </ul>
*/
public interface TimeSeries extends Serializable {
/**
* @return the name of the series
*/
String getName();
/**
* @param i an index
* @return the bar at the i-th position
*/
Bar getBar(int i);
/**
* @return the first bar of the series
*/
default Bar getFirstBar() {
return getBar(getBeginIndex());
}
/**
* @return the last bar of the series
*/
default Bar getLastBar() {
return getBar(getEndIndex());
}
/**
* @return the number of bars in the series
*/
int getBarCount();
/**
* @return true if the series is empty, false otherwise
*/
default boolean isEmpty() {
return getBarCount() == 0;
}
/**
* Warning: should be used carefully!
* <p>
* Returns the raw bar data.
* It means that it returns the current List object used internally to store the {@link Bar bars}.
* It may be:
* - a shortened bar list if a maximum bar count has been set
* - a extended bar list if it is a constrained time series
* @return the raw bar data
*/
List<Bar> getBarData();
/**
* @return the begin index of the series
*/
int getBeginIndex();
/**
* @return the end index of the series
*/
int getEndIndex();
/**
* @return the description of the series period (e.g. "from 12:00 21/01/2014 to 12:15 21/01/2014")
*/
default String getSeriesPeriodDescription() {
StringBuilder sb = new StringBuilder();
if (!getBarData().isEmpty()) {
Bar firstBar = getFirstBar();
Bar lastBar = getLastBar();
sb.append(firstBar.getEndTime().format(DateTimeFormatter.ISO_DATE_TIME))
.append(" - ")
.append(lastBar.getEndTime().format(DateTimeFormatter.ISO_DATE_TIME));
}
return sb.toString();
}
/**
* Sets the maximum number of bars that will be retained in the series.
* <p>
* If a new bar is added to the series such that the number of bars will exceed the maximum bar count,
* then the FIRST bar in the series is automatically removed, ensuring that the maximum bar count is not exceeded.
* @param maximumBarCount the maximum bar count
*/
void setMaximumBarCount(int maximumBarCount);
/**
* @return the maximum number of bars
*/
int getMaximumBarCount();
/**
* @return the number of removed bars
*/
int getRemovedBarsCount();
/**
* Adds a bar at the end of the series.
* <p>
* Begin index set to 0 if if wasn't initialized.<br>
* End index set to 0 if if wasn't initialized, or incremented if it matches the end of the series.<br>
* Exceeding bars are removed.
* @param bar the bar to be added
* @see TimeSeries#setMaximumBarCount(int)
*/
void addBar(Bar bar);
/**
* Returns a new TimeSeries implementation that is a subset of this TimeSeries implementation.
* It holds a copy of all {@link Bar bars} between <tt>startIndex</tt> (inclusive) and <tt>endIndex</tt> (exclusive)
* of this TimeSeries.
* The indices of this TimeSeries and the new subset TimeSeries can be different. I. e. index 0 of the new TimeSeries will
* be index <tt>startIndex</tt> of this TimeSeries.
* If <tt>startIndex</tt> < this.seriesBeginIndex the new TimeSeries will start with the first available Bar of this TimeSeries.
* If <tt>endIndex</tt> > this.seriesEndIndex the new TimeSeries will end at the last available Bar of this TimeSeries
* @param startIndex the startIndex
* @param endIndex the endIndex
* @return a new BaseTimeSeries with Bars from startIndex to endIndex-1
* @throws IllegalArgumentException e.g. if endIndex < startIndex
*/
TimeSeries getSubSeries(int startIndex, int endIndex);
}
解决方案
接口中的所有方法声明,包括静态方法,都是隐式公共的。它通常被省略。
实现类应该保留这个修饰符,而不是使用默认的类方法 modifer( package level
)。
您可以将其更改为:
public String getName()
{
return "TestSet";
}
推荐阅读
- oracle - 如何回滚我的 Oracle PL/SQL 调试会话 (SQL Developer)
- python - Python:使用两个列表制作字典
- excel - 确保用户在开始编辑内容时打开工作簿以进行编辑
- html - 打开控制台后如何防止 HTML 元素移动
- sql - 有没有办法遍历要在 Ecto 查询中选择的属性列表?
- sql - SQL注入中如何选择第二行?
- r - 是否可以在 LaTeX 中使用 roxygen 注释?
- vb.net - OpenFileDialog1_FileOk 事件返回 NullReferenceException
- html - 为什么flexbox 内的宽度没有正确更新?
- matlab - 如何对两个 4 位数字进行乘法运算,将它们视为 MATLAB 中的多项式