Reputation: 1678
I have created a new class 'ServiceRequest' like below. I have not added getters and setters here to save space.
package testListenerPackage;
import java.util.Date;
public class ServiceRequest {
public static final ServiceRequest REQUEST_ARRIVAL = new ServiceRequest( "Request_Arrival" );
public static final ServiceRequest REQUEST_COMPLETION = new ServiceRequest( "Request_Completion" );
public static final ServiceRequest REQUEST_UNDER_PROCESS = new ServiceRequest( "Request_Under_Process" );
private String serviceRequest;
private String requestName;
private int requestID;
private long arrivalTime;
private long startServiceTime;
private long endServiceTime;
private long totalServiceTime;
private String requestStatus;
public enum RequestStatus{
NEW, COMPLETED
}
public ServiceRequest()
{
}
public ServiceRequest( String serviceRequest ) {
serviceRequest = serviceRequest;
}
}
When I try to create an instance of this object in other class like this, it returns a null object.
public ServiceRequest generateServiceRequest()
{
ServiceRequest serviceRequest = new ServiceRequest("Ali baba");
serviceRequest.setRequestID(1);
serviceRequest.setRequestName("Read");
serviceRequest.setRequestStatus(ServiceRequest.REQUEST_ARRIVAL.toString());
serviceRequest.setArrivalTime(System.currentTimeMillis());
return serviceRequest;
}
Can anybody tell me what to do?
Upvotes: 0
Views: 3237
Reputation: 1410
when he meant "null object", he meant that object has nothing in it (his serviceRequest string). As Beau Grantham said "this" will get job done
Upvotes: 0
Reputation: 308763
I don't like this code:
public ServiceRequest()
{
// all those references are null - crazy
}
public ServiceRequest(String serviceRequest ) {
// use "this" to clarify what's initialized
this.serviceRequest = serviceRequest;
}
Upvotes: 1