Question

I'm working on a Java project I didn't code, written with Tapestry 4. Here's an example of some code:

@Persist
public abstract String getParentClientId();
public abstract void setParentClientId(String str);

My knowledge of Java is limited. I'm accustomed to seeing getters return something and setters, well, set something. There's no {} used to define these methods and no code between them like I expect. Is there some convention I'm missing? Perhaps getParentClientId() implicitly returns the value of ParentClientId, or something of the like? Any info you have would be great. Thanks!

Was it helpful?

Solution

those are abstract methods that's why they dont have any implementation. To know more about the abstract class and methods see Oracle's documentation on Abstract Methods:

An abstract method is a method that is declared without an implementation (without braces, and followed by a semicolon), like this:

abstract void moveTo(double deltaX, double deltaY);

When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class. However, if it does not, the subclass must also be declared abstract.

OTHER TIPS

typical implementation of setter and getter is:

public String getParentClientId() { return parentClientId;}

public void setParentClientId(String str){ parentClientId = str;}

If method have abstract modifier means that it should be implmeneted in subclass

Your methods are abstract, and you must to realiaze tham)

The methods are defined as abstract hence there is no code with it.

Maybe some tapestry API will implement these abstract method by creating dynamic classes as you have used @Persist for getParentClientId(). If these methods are working in your code then this must be the case.

Those are abstract classes. They are used to define methods that have to be present on any instance of that class, but are different for each subclass. They are actually defined in subclasses.
Of course no objects of the class that defines the abstract methods can be created, as it wouldn't have an implementation of that methods. Therefore, only abstract classes can include abstract methods - and one can never create instances of abstract classes.

I 'm not a Tapestry 4 user but, as far as I know Tapestry 4 used a lot of abstract method declarations to hook functionality you don't have to code (as getters/setters for example).

Afterwards Tapestry 4 would create a new class in runtime that inherits your class and implements some of the abstract methods you declared (based in certain Tapestry 4 convention).

I 'm a Tapestry 5 user, and in this new version abstract methods are not required by the framework they 've changed the way the runtime created classes are created (they 're now using the Plastic framework, and previously javassist) in order to avoid those rare abstract declarations in favor of use of brand new Annotations.

If you have the time to migrate to T5 don't doubt it!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top