Java — Marker Interfaces in Java | Code Factory

Custom Marker Interface

public interface Deletable {

}
public class Entity implements Deletable {
// implementation details
}
public class ShapeDao {    // other dao methods

public boolean delete(Object object) {
if (!(object instanceof Deletable)) {
return false;
}

// delete implementation details

return true;
}
}

Marker Interfaces vs. Annotations

public interface Shape {
double getArea();
double getCircumference();
}
public interface DeletableShape extends Shape {

}
public class Rectangle implements DeletableShape {
// implementation details
}

Marker Interfaces vs. Typical Interfaces

public class ShapeDao {    // other dao methods

public boolean delete(Object object) {
if (!(object instanceof Shape)) {
return false;
}

// delete implementation details

return true;
}
}
public boolean delete(Object object) {
if (!(object instanceof Shape || object instanceof Person)) {
return false;
}

// delete implementation details

return true;
}

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Overlay Foundation, PlanckCat DAO, and How Governance will work

Data Visualisation

DeHive Enables Yield Farming for Poly Gaming Cluster 🔥🤑

Working with my Brother — Part 1

Stacks of office paper.

Why you arent reaching your full cloud management potential

Resumable Uploader

The Importance of Continuous Integration and Continuous Delivery

Spotify Mac Skip F9

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Code Factory

Code Factory

More from Medium

Annotations In Java

Features of Java 8 to 18

Code Coverage for Java — Jacoco