这是什么意思?“不赞成使用此方法,因为用户应使用Java 5约定。”? [英] What does this mean "This method is deprecated as the user should use the Java 5 conventions."?

查看:111
本文介绍了这是什么意思?“不赞成使用此方法,因为用户应使用Java 5约定。”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 opencvs 库的 ColumnPositionMappingStrategy类。
此类已弃用 方法 setType(Class< T> type),并且注释中带有 不建议使用此方法,因为用户应使用Java 5约定

I am using the "ColumnPositionMappingStrategy" class of the opencvs library. This class has the deprecated method setType(Class<T> type) and as comment has "This method is deprecated as the user should use the Java 5 conventions"

据我了解,我必须使用泛型而不是setType例如:

As far as I understand is that I have to use Generics instead of setType like:

ColumnPositionMappingStrategy<MyClass> mappingStrategy = new ColumnPositionMappingStrategy<>();

解决问题。但是删除行时得到 NullPointerException

to solve the problem. But I get NullPointerException when I remove the line:

mappingStrategy.setType(MyClass.class);

错误:

java.lang.RuntimeException: Error parsing CSV!
at com.opencsv.bean.CsvToBean.parse(CsvToBean.java:95)
at com.opencsv.bean.CsvToBean.parse(CsvToBean.java:75)
at csv_import.ReadCsvFile.readRecordData(ReadCsvFile.java:40)
at app.Application.main(Application.java:30)

Caused by: java.lang.NullPointerException
at com.opencsv.bean.HeaderColumnNameMappingStrategy.createBean(HeaderColumnNameMappingStrategy.java:170)
at com.opencsv.bean.CsvToBean.processLine(CsvToBean.java:117)
at com.opencsv.bean.CsvToBean.processLine(CsvToBean.java:101)
at com.opencsv.bean.CsvToBean.parse(CsvToBean.java:91)
... 3 more

我该怎么做才能解决此问题?

What do I have to do to solve this problem?

推荐答案

实现依赖于该类型,方法是调用:

The implementation relies on the type by calling:

public T createBean() throws InstantiationException, IllegalAccessException {
  return type.newInstance();
}

像这样的一些注释- TODO重构此类-暗示 @Deprecation 批注使用得太早了-因为没有其他用法。

Some comments like this one - TODO refactor this class to use T instead of getType. - imply that the @Deprecation annotations have been used too early - as there is no alternative usage available.

这篇关于这是什么意思?“不赞成使用此方法,因为用户应使用Java 5约定。”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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