我无法编译下面的代码,因为我有 17 个关于“无法从静态上下文引用的非静态变量”的错误。它总是指向this
关键字。
package MyLib;
import java.util.*;
class Book {
static int pages;
static String Title;
static String Author;
static int status;
static String BorrowedBy;
static Date ReturnDate;
static Date DueDate;
public static final int
BORROWED = 0;
public static final int
AVAILABLE = 1;
public static final int
RESERVED = 2;
//constructor
public Book ( String Title, String Author, int pp) {
this.Title = Title;
this.Author = Author;
this.pages = pp;
this.status = this.AVAILABLE;
}
public static void borrow(String Borrower/*, Date Due*/){
if (this.status=this.AVAILABLE){
this.BorrowedBy=Borrower;
this.DueDate=Due;
}
else {
if(this.status == this.RESERVED && this.ReservedBy == Borrower){
this.BorrowedBy= Borrower;
this.DueDate=Due;
this.ReservedBy="";
this.status=this.BORROWED;
}
}
}