java 重写方法报错

2019-03-20 1447 星期三

异常提醒

Name clash: The method setData(List<Object>) of type new PagedResult(){} 
has the same erasure as setData(List) of type PagedResult but does not override it

pagedResult.java

package com.china.demo.platform.common.vo;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.china.demo.platform.common.exception.BaseException;

@SuppressWarnings({"unchecked","rawtypes"})
public class PagedResult<T>{
	private List<T> data;
	private long total;
	private PageInfo info;
	private Map<String, Object> addtions;
	  
	public PagedResult(List<T> data, long total, int pageIndex, int pageSize){
	    this.data = data;
	    this.total = total;
	    this.info = new PageInfo(pageIndex, pageSize, total);
	}
	
	public static final PagedResult<Object> EMPTY = new PagedResult(Collections.emptyList(), 0L, 1, 10)  {
	    /**
	     * 2019-03-20 1443 出现异常 
	     * Name clash: The method setData(List<Object>) of type new PagedResult(){} 
	     * 	 has the same erasure as setData(List) of type PagedResult but does not override it
	     */
		public void setData(List<Object> data){
	    	throw new BaseException("不允许调用EMPTY的setData()方法!");
	    }
	    public void setTotal(long total){
	      throw new BaseException("不允许调用EMPTY的setTotal()方法!");
	    }
	};
 
  
  public List<T> getData(){
    return this.data;
  }
  
  public void setData(List<T> data){
    this.data = data;
  }
  
  public long getTotal(){
    return this.total;
  }
  
  public void setTotal(long total) {
    this.total = total;
  }
  
  public PageInfo getInfo()  {

    return this.info;
  }
  
  public void putAddition(String key, Object value) {
    if (this.addtions == null) {
      this.addtions = new HashMap();
    }
    this.addtions.put(key, value);
  }
  
  public Map<String, Object> getAdditions()  {
    if (this.addtions != null) {
      return Collections.unmodifiableMap(this.addtions);
    }
    return null;
  }
}

PageInfo.java

package com.china.demo.platform.common.vo;

public class PageInfo
{
  private int next;
  private int prev;
  private int totalPage;
  private int pageIndex;
  private int pageSize;
  
  public PageInfo(int pageIndex, int pageSize, long total)
  {
    this.pageIndex = pageIndex;
    this.pageSize = pageSize;
    this.totalPage = ((int)(total / pageSize));
    if (total % pageSize != 0L) {
      this.totalPage += 1;
    }
    this.next = (pageIndex >= this.totalPage ? pageIndex : pageIndex + 1);
    this.prev = (pageIndex < 2 ? 1 : pageIndex - 1);
  }
  
  public int getNext()
  {
    return this.next;
  }
  
  public int getPrev()
  {
    return this.prev;
  }
  
  public int getFirst()
  {
    return 1;
  }
  
  public int getLast()
  {
    return this.totalPage;
  }
  
  public int getTotalPage()
  {
    return this.totalPage;
  }
  
  public int getPageIndex()
  {
    return this.pageIndex;
  }
  
  public int getPageSize()
  {
    return this.pageSize;
  }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值