Skip to main content

One post tagged with "inheritance"

View All Tags

Spring Data JPA Part 5: Why UserRepository MUST Be an Interface - Java Type System Rules

· 8 min read
Mahmut Salman
Software Developer

"Why can't I use class instead of interface for UserRepository?" Because Java's type system has strict rules: class extends class, interface extends interface, class implements interface. When you try class UserRepository extends JpaRepository, Java sees JpaRepository is an interface and throws an error. Let's understand the three-level inheritance chain and who implements what.