Tuesday, 15 January 2013

Java generics on super class but not all subclasses want to define a type parameter -


I did not know how well this title ... I hope the motivation will come later and I will I can update, but ...

Describe me with some (pseudo) code:

I try to manage AJAX requests on my server in a fair way This is what I have come up with.

Aadhaar Request:

  Public Essential Class BasRQuest & lt; T & gt; {Private last T statement; Public Security (T details) {this.details = details; } Public abstract void process (); }  

Then I have a request that some data is coming up, it says that this is for a login request where log in details a bean Is:

  public class LoginRequest expanded the baserxtest & lt; LoginDetails & gt; {Public Login Route (T Description) {Super (Details); } / ** * @ Override * / Public Zero Process () {Toolbox.login (this.details); }}  

It has been working hard to do so ... I have various requests where I take the form of data on beans and using these futures they have them in these requests I do All are good ... as long as ...

I decide to request logout. There should be no data to be connected to any bean for this request and therefore I defined a type parameter I do not want to do it (it will break everything). Something like this is what I want to be able to do:

  public class logout request bassAccest {public logout request () {super (empty); } / ** * @ Override * / Public Zero Process () {Toolbox.logout (); }}  

And when it compiles and works it crawls my skin due to security.

Now ... I know how to solve it, but I'm wondering if there was a better way.

My solution

should be an in-built base request and a typed subclass of it, which is the data request sub-class and the logout request only Unlitten base will leave the request.

Unlimited Base Requests:

  Public Essentials Base BaseRequest {public abstract void process (); }  

A base data request has been typed:

  Public abstract class BaseDataRequest & lt; T & gt; BaseRequest extended {personal last T statement; Public BaseDataRequest (T details) {this.details = details; }}  

Then login:

  Public class LoginRequest has requested the bassdatindest & lt; LoginDetails & gt; {Public Login Route (T Description) {Super (Details); } / ** * @ Override * / Public Zero Process () {Toolbox.login (this.details); }}  

and logout:

  Public class logout request extends uncooked quota {/ ** * @ override * / public zero process () { Toolbox.logout (); }}  

I want to make sure that my solution is the best option and I have not left any way to specify the type of tap (I know that this concept is not present) or Anyone else like that crazy can confirm for me.

In addition to this, I am taking suggestions for an updated title for the question.

You were on the right track with some kind of thinking. Such a thing is not present in Java, but in Java.

Zero class is an unreachable placeholder class to reference class object representing zero squared.

You can create type parameter Zero , so that only zero can be sent to the Superclass constructor in calls.

Public Class Logout Request BaseRequest and Lieutenant; VioOD & gt; {Public logout () {super (tap); }}

No comments:

Post a Comment