View Single Post
  #4   Spotlight this post!  
Unread 02-07-2016, 23:05
RyanCahoon's Avatar
RyanCahoon RyanCahoon is offline
Disassembling my prior presumptions
FRC #0766 (M-A Bears)
 
Join Date: Dec 2007
Rookie Year: 2007
Location: Mountain View
Posts: 689
RyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond reputeRyanCahoon has a reputation beyond repute
Re: To extend Function or not to extend Function

+1 to what has already been said. It's up to each code implementor to ensure that the proper functionality is in place, and up to reach consumer of code that others have written to ensure that code does what they want.

To offer concrete proof that this isn't possible in Java:

Suppose there were a way to enforce what you're asking for
Code:
public interface A<T> /* magic that requires subclass of A to use itself as the type parameter */ {
public T interpolate(T a);
}
Since there's no way in Java to require a subclass to be final, nothing prevents a malicious user from doing the following
Code:
class B extends A<B> {
public B interpolate(B a){
// implementation
}
}

class C extends B {}
at this point, C is equivalent to
Code:
class C extends A<B>
__________________
FRC 2046, 2007-2008, Student member
FRC 1708, 2009-2012, College mentor; 2013-2014, Mentor
FRC 766, 2015-, Mentor
Reply With Quote