java - StringBuilder and CharSequence incompatible -


i'm beginner in java language , following oracle java tutorial gain more insight of language. when i'm studying interface part, got confused when tried exercise:

"write class implements charsequence interface found in java.lang package. implementation should return string backwards. select 1 of sentences book use data. write small main method test class; make sure call 4 methods."

when i'm doing this, found strange. @ first, download java.lang.charsequence interface source code , add interface file in home directory, , my implementation of 'subsequence' complains stringbuilder cannot casted charsequence type.

here code:

public charsequence subsequence(int start, int end) {     if (start < 0) {         throw new stringindexoutofboundsexception(start);     }     if (end > s.length()) {         throw new stringindexoutofboundsexception(end);     }     if (start > end) {         throw new stringindexoutofboundsexception(start - end);     }     stringbuilder sub =          new stringbuilder(s.subsequence(fromend(end), fromend(start)));     return sub.reverse(); } 

but when delete local file of charsequence interface, java compiler finds out i'm implementing 'java.lang.charsequence' interface instead of local package, then compiling error disappears.

just curious this. what's difference between local interface file , library interface file? , causes compiling error in beginning?

there no such thing "local interface file".

you made new, unrelated interface happens have same name interface in jre.

you use types defined in jre directly packages, without downloading anything.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -