Eclipse 收集器找不到字段
我尝试使用lambda来平均一个字段与另一个分组字段。它失败了,说找不到现场价格。它确实可以毫无问题地找到tradeMinutes字段。这会让我相信它现在做的是正确的类 eclipse中的编译错误Eclipse 收集器找不到字段,eclipse,lambda,java-8,Eclipse,Lambda,Java 8,我尝试使用lambda来平均一个字段与另一个分组字段。它失败了,说找不到现场价格。它确实可以毫无问题地找到tradeMinutes字段。这会让我相信它现在做的是正确的类 eclipse中的编译错误 Exception in thread "main" java.lang.Error: Unresolved compilation problem: price cannot be resolved or is not a field at com.simplegrowth.as
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
price cannot be resolved or is not a field
at com.simplegrowth.assets.AssetAdder.<init>(AssetAdder.java:60)
at com.simplegrowth.Reader.<clinit>(Reader.java:23)
线程“main”java.lang中出现异常。错误:未解决的编译问题:
无法解析价格或价格不是字段
位于com.simplegrowth.assets.assetader.(assetader.java:60)
位于com.simplegrowth.Reader。(Reader.java:23)
组列表函数
List<Asset> assetsList = null;
assetsList = assets.get("BILL");
assetsList.stream()
.collect(Collectors.groupingBy( a -> a.tradeMinutesSinceMidnight, Collectors.averagingDouble( a -> a.price) ) )
.forEach(( tradeMinutesSinceMidnight, sumPrice) -> System.out.println(tradeMinutesSinceMidnight + " " + sumPrice));
List assetsList=null;
assetsList=assets.get(“票据”);
assetsList.stream()
.collect(Collector.groupingBy(a->a.tradeMinutesSinceMidnight,Collector.averagingDouble(a->a.price)))
.forEach((tradeMinutesSinceMidnight,sumPrice)->System.out.println(tradeMinutesSinceMidnight+“”+sumPrice));
资产类别
public class Asset implements Serializable, Comparable<Asset> {
private static final long serialVersionUID = 1L;
@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id; // still set automatically
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
long sequenceNo;
String Exchange;
String Board;
long time;
String paper;
long tradeTime;
long quantity;
double price;
String source;
String buyer;
String seller;
float changeSinceLast;
String initator;
long tradeTimeSinceMidnight;
long tradeMinutesSinceMidnight;
long daysSinceEpoch;
public long getSequenceNo() {
return sequenceNo;
}
public void setSequenceNo(long sequenceNo) {
this.sequenceNo = sequenceNo;
}
public String getExchange() {
return Exchange;
}
public void setExchange(String exchange) {
Exchange = exchange;
}
public String getBoard() {
return Board;
}
public void setBoard(String board) {
Board = board;
}
public long getTime() {
return time;
}
public void setTime(long time) {
this.time = time;
}
public String getPaper() {
return paper;
}
public void setPaper(String paper) {
this.paper = paper;
}
public long getTradeTime() {
return tradeTime;
}
public void setTradeTime(long tradeTime) {
this.tradeTime = tradeTime;
}
public long getQuantity() {
return quantity;
}
public void setQuantity(long quantity) {
this.quantity = quantity;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public String getBuyer() {
return buyer;
}
public void setBuyer(String buyer) {
this.buyer = buyer;
}
public String getSeller() {
return seller;
}
public void setSeller(String seller) {
this.seller = seller;
}
public float getChangeSinceLast() {
return changeSinceLast;
}
public void setChangeSinceLast(float changeSinceLast) {
this.changeSinceLast = changeSinceLast;
}
public String getInitator() {
return initator;
}
public void setInitator(String initator) {
this.initator = initator;
}
public long getDaysSinceEpoch() {
return daysSinceEpoch;
}
public void setDaysSinceEpoch(long daysSinceEpoch) {
this.daysSinceEpoch = daysSinceEpoch;
}
public long getTradeTimeSinceMidnight() {
return tradeTimeSinceMidnight;
}
public void setTradeTimeSinceMidnight(long tradeTimeSinceMidnight) {
this.tradeTimeSinceMidnight = tradeTimeSinceMidnight;
}
public long getTradeMinutesSinceMidnight() {
return tradeMinutesSinceMidnight;
}
public void setTradeMinutesSinceMidnight(long tradeMinutesSinceMidnight) {
this.tradeMinutesSinceMidnight = tradeMinutesSinceMidnight;
}
@Override
public boolean equals(Object obj) {
if (sequenceNo == ((Asset)obj).sequenceNo)
return true;
return false;
//return super.equals(obj);
}
@Override
public int compareTo(Asset otherAsset) {
if (this.getSequenceNo() < otherAsset.getSequenceNo()) {
return -1;
}
return 1;
}
}
公共类资产实现了可序列化、可比较的{
私有静态最终长serialVersionUID=1L;
@Id@GeneratedValue(策略=GenerationType.IDENTITY)
private Long id;//仍然自动设置
公共长getId(){
返回id;
}
公共无效集合id(长id){
this.id=id;
}
长序列号;
字符串交换;
线板;
长时间;
线纸;
交易时间长;
数量多;
双倍价格;
字符串源;
弦乐买家;
线人;
漂浮物变化;
字符串启动器;
从午夜开始的漫长时间;
从午夜开始的漫长交易;
长日照期;
公共长getSequenceNo(){
返回序列号;
}
公共无效序列号(长序列号){
this.sequenceNo=sequenceNo;
}
公共字符串getExchange(){
换汇;
}
公共无效集合交换(字符串交换){
交换=交换;
}
公共字符串getBoard(){
返回板;
}
公共空隙立根板(线板){
董事会=董事会;
}
公共长getTime(){
返回时间;
}
公共无效设置时间(长时间){
这个时间=时间;
}
公共字符串getPaper(){
回执纸;
}
公共空白衬纸(线纸){
这张纸=纸;
}
公共长时间(){
返回时间;
}
公共无效设置交易时间(长交易时间){
this.tradeTime=交易时间;
}
公共长getQuantity(){
退货数量;
}
公共无效设置数量(长数量){
这个。数量=数量;
}
公开双价{
退货价格;
}
公共定价(双倍价格){
这个价格=价格;
}
公共字符串getSource(){
返回源;
}
公共void集合源(字符串源){
this.source=源;
}
公共字符串getBuyer(){
退货买家;
}
公共买方(字符串买方){
这个。买方=买方;
}
公共字符串getSeller(){
退货卖家;
}
公共无效设置卖方(字符串卖方){
this.seller=卖方;
}
公共浮点getChangeSinceLast(){
最后的回报变化;
}
公共无效设置更改最后一次(浮动更改最后一次){
this.changeSinceLast=changeSinceLast;
}
公共字符串getInitator(){
返回启动器;
}
公共void setInitator(字符串initator){
this.initator=initator;
}
公共长getDaysSinceEpoch(){
返回日期;返回时间;
}
公共无效setDaysSinceEpoch(长daysSinceEpoch){
this.daysSinceEpoch=daysSinceEpoch;
}
公共长getTradeTimeSinceMidnight(){
午夜返回;
}
public void setTradeTimeSinceMidnight(长tradeTimeSinceMidnight){
this.tradeTimeSinceMidnight=tradeTimeSinceMidnight;
}
公共long getTradeMinutesSinceMidnight(){
午夜后返回交易记录;
}
公共无效设置tradeMinutesSinceMidnight(长tradeMinutesSinceMidnight){
this.tradeMinutesSinceMidnight=tradeMinutesSinceMidnight;
}
@凌驾
公共布尔等于(对象obj){
if(sequenceNo==((资产)对象).sequenceNo)
返回true;
返回false;
//返回super.equals(obj);
}
@凌驾
公共整数比较(资产其他资产){
if(this.getSequenceNo()
它使用javac编译起来很好。您正在使用Eclipse吗?作为旁注,您的compareTo
方法被破坏了。如果对象相等,则应返回0
。而且您的equals
方法并不复杂。只需说returnsequenceno==((资产)obj)代码>是的,我正在使用eclipse。因此,您可以尝试使用收集器来帮助那个可怜的eclipse编译器。averagingDouble(a->a.price)
,或者等待更新……这样做了,非常好。不知道eclipse可能无法使用标准编译器