When to use CharSequence in an API

前端 未结 5 1277
囚心锁ツ
囚心锁ツ 2020-12-14 08:14

I\'m designing a public interface (API) for a package. I wonder, should I use CharSequence generally instead of String. (I\'m mainly talking about

5条回答
  •  独厮守ぢ
    2020-12-14 08:46

    Java CharSequence is an interface. As the API says, CharSequence has been implemented in CharBuffer, Segment, String, StringBuffer, StringBuilder classes. So if you want to access or accept your API from all these classes thenCharSequence is your choice. If not then String is very good for a public API because it is very easy & everybody knows about it. Remember CharSequence only gives you 4 method, so if you are accepting a CharSequence object through a method, then your input manipulation ability will be limited.

提交回复
热议问题