简体   繁体   中英

Why are methods of extended interface not visible in class that implements extending interface?

I have an issue with the java.time API, specifically the LocalDate.

LocalDate implements ChronoLocalDate and this implements Comparable.

When I do something like

LocalDate now = LocalDate.now();
now.getClass().getInterfaces();

It only lists me the interfaces directly at LocalDate, but not the ones that are inherited by ChronoLocalDate. Why is this the case?

Add-On: My original issue is that I have a generic class working on types that implement comparable, but this obviously does not work with LocalDate as it does not implement Comparable directly.

Here is the definition of the generic class:

public final class Range<T extends Comparable<T> & Serializable> implements Serializable

What would I need to do to make this generic class definition work for LocalDate type?

Should't your definition look more like this:

static final class Range<T extends Comparable<? super T> &   
          Serializable> implements Serializable {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM