You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tamaya.apache.org by "Oliver B. Fischer" <o....@swe-blog.net> on 2014/12/01 09:12:56 UTC

CharSequence instead of String

Hi,

after our dicussing the data type conversion topic I got the impression 
what we should use

1. CharSequence as basic data type

Is this true for all of us?

How does it affect our API? Should we use CharSequence consistently in 
our API?

wdyt?

Oliver

-- 
N Oliver B. Fischer
A Schönhauser Allee 64, 10437 Berlin, Deutschland/Germany
P +49 30 44793251
M +49 178 7903538
E o.b.fischer@swe-blog.net
S oliver.b.fischer
J oliver.b.fischer@jabber.org
X http://xing.to/obf


Re: CharSequence instead of String

Posted by Romain Manni-Bucau <rm...@gmail.com>.
issue is doing getMethod("valueof", CharSequence.class) you'll not find it.

Once again it is not a question of is it good or bad (I could say you
usage of String is >>> CharSequence as well), it is just to be aligned
with common usages.

BTW: supporting both is trivial so not sure we need to discuss for ages.


Romain Manni-Bucau
@rmannibucau
http://www.tomitribe.com
http://rmannibucau.wordpress.com
https://github.com/rmannibucau


2014-12-01 10:02 GMT+01:00 Otávio Gonçalves de Santana
<ot...@gmail.com>:
> I don't see any problem doing this way,  many api has been used this
> strategy, because is a good practice use interface instead implementation.
>
> And in CharSequence interface we have the method to convert to String.
>
> https://docs.oracle.com/javase/8/docs/api/java/lang/CharSequence.html
>
> Some Examples:
>
> https://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html#parse-java.lang.CharSequence-
>
> https://github.com/JavaMoney/jsr354-ri/blob/master/src/main/java/org/javamoney/moneta/Money.java
>
> https://github.com/JavaMoney/jsr354-api/blob/master/src/main/java/javax/money/format/MonetaryAmountFormat.java
>
>
> On Dec 1, 2014 6:14 AM, "Oliver B. Fischer" <o....@swe-blog.net>
> wrote:
>
>> Hi,
>>
>> after our dicussing the data type conversion topic I got the impression
>> what we should use
>>
>> 1. CharSequence as basic data type
>>
>> Is this true for all of us?
>>
>> How does it affect our API? Should we use CharSequence consistently in our
>> API?
>>
>> wdyt?
>>
>> Oliver
>>
>> --
>> N Oliver B. Fischer
>> A Schönhauser Allee 64, 10437 Berlin, Deutschland/Germany
>> P +49 30 44793251
>> M +49 178 7903538
>> E o.b.fischer@swe-blog.net
>> S oliver.b.fischer
>> J oliver.b.fischer@jabber.org
>> X http://xing.to/obf
>>
>>

Re: CharSequence instead of String

Posted by Otávio Gonçalves de Santana <ot...@gmail.com>.
I don't see any problem doing this way,  many api has been used this
strategy, because is a good practice use interface instead implementation.

And in CharSequence interface we have the method to convert to String.

https://docs.oracle.com/javase/8/docs/api/java/lang/CharSequence.html

Some Examples:

https://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html#parse-java.lang.CharSequence-

https://github.com/JavaMoney/jsr354-ri/blob/master/src/main/java/org/javamoney/moneta/Money.java

https://github.com/JavaMoney/jsr354-api/blob/master/src/main/java/javax/money/format/MonetaryAmountFormat.java


On Dec 1, 2014 6:14 AM, "Oliver B. Fischer" <o....@swe-blog.net>
wrote:

> Hi,
>
> after our dicussing the data type conversion topic I got the impression
> what we should use
>
> 1. CharSequence as basic data type
>
> Is this true for all of us?
>
> How does it affect our API? Should we use CharSequence consistently in our
> API?
>
> wdyt?
>
> Oliver
>
> --
> N Oliver B. Fischer
> A Schönhauser Allee 64, 10437 Berlin, Deutschland/Germany
> P +49 30 44793251
> M +49 178 7903538
> E o.b.fischer@swe-blog.net
> S oliver.b.fischer
> J oliver.b.fischer@jabber.org
> X http://xing.to/obf
>
>

Re: CharSequence instead of String

Posted by Andres Almiray <aa...@gmail.com>.
This is what I'm thinking: a Groovy based configuration space defines a
key/value pair in the following manner

my.weird.groovy.key = "This is some ${adjective} value"

This happens to be a Groovy String. This kind of strings extend directly
from CharSequence and can be converted on the fly to java.lang.String.
The use case is to receive the Groovy String as is, iow, you don't want
conversion to happen. If you do you may encounter a runtime error because
the value of the free variable (adjective) may not be bound.
If the target property is of type CharSequence then the Groovy String can
be applied to it with no type conversion. If the type is String then
conversion takes place and it will most likely fail

Cheers,
Andres


-------------------------------------------
Java Champion; Groovy Enthusiast
http://jroller.com/aalmiray
http://www.linkedin.com/in/aalmiray
--
What goes up, must come down. Ask any system administrator.
There are 10 types of people in the world: Those who understand binary, and
those who don't.
To understand recursion, we must first understand recursion.

On Mon, Dec 1, 2014 at 5:23 PM, Oliver B. Fischer <o....@swe-blog.net>
wrote:

> @Andres: You mentioned that Groovy could benefit from it. Could you
> explain it a little bit more so that we could decide based on some usecases?
>
> Oliver
>
> Am 01.12.14 16:13, schrieb Tresch, Anatole:
>
>  +1 String support is mandatory. CharSequence for me, often is a good
>> thing, but sometimes also is simply not needed. Typically it is very
>> useful, where you have some kind of String handling in place, as it is
>> typical for parsing or formatting. In cases where you typically pass
>> constant keys only, I see only limited advantages (or even disadvantages by
>> bloating the API, creating unnecessary Strings ...).
>>
>> So I would ask for concrete proposals where to add it, so we can focus
>> discussion on the concrete cases ;)
>>
>> -Anatole
>>
>>
>>
>> -----Original Message-----
>> From: Romain Manni-Bucau [mailto:rmannibucau@gmail.com]
>> Sent: Montag, 1. Dezember 2014 09:43
>> To: dev@tamaya.incubator.apache.org
>> Subject: Re: CharSequence instead of String
>>
>> think we should support String so CharSequence would be another
>> supported type. Main reason is valueOf(String) or fromString(String)
>> is common in several specs.
>>
>> No issues supporting both but not supporting string would be quite
>> uncommon for me, wdyt?
>>
>>
>> Romain Manni-Bucau
>> @rmannibucau
>> http://www.tomitribe.com
>> http://rmannibucau.wordpress.com
>> https://github.com/rmannibucau
>>
>>
>> 2014-12-01 9:12 GMT+01:00 Oliver B. Fischer <o....@swe-blog.net>:
>>
>>> Hi,
>>>
>>> after our dicussing the data type conversion topic I got the impression
>>> what
>>> we should use
>>>
>>> 1. CharSequence as basic data type
>>>
>>> Is this true for all of us?
>>>
>>> How does it affect our API? Should we use CharSequence consistently in
>>> our
>>> API?
>>>
>>> wdyt?
>>>
>>> Oliver
>>>
>>> --
>>> N Oliver B. Fischer
>>> A Schönhauser Allee 64, 10437 Berlin, Deutschland/Germany
>>> P +49 30 44793251
>>> M +49 178 7903538
>>> E o.b.fischer@swe-blog.net
>>> S oliver.b.fischer
>>> J oliver.b.fischer@jabber.org
>>> X http://xing.to/obf
>>>
>>>
> --
> N Oliver B. Fischer
> A Schönhauser Allee 64, 10437 Berlin, Deutschland/Germany
> P +49 30 44793251
> M +49 178 7903538
> E o.b.fischer@swe-blog.net
> S oliver.b.fischer
> J oliver.b.fischer@jabber.org
> X http://xing.to/obf
>
>

Re: CharSequence instead of String

Posted by "Oliver B. Fischer" <o....@swe-blog.net>.
@Andres: You mentioned that Groovy could benefit from it. Could you 
explain it a little bit more so that we could decide based on some usecases?

Oliver

Am 01.12.14 16:13, schrieb Tresch, Anatole:
> +1 String support is mandatory. CharSequence for me, often is a good thing, but sometimes also is simply not needed. Typically it is very useful, where you have some kind of String handling in place, as it is typical for parsing or formatting. In cases where you typically pass constant keys only, I see only limited advantages (or even disadvantages by bloating the API, creating unnecessary Strings ...).
>
> So I would ask for concrete proposals where to add it, so we can focus discussion on the concrete cases ;)
>
> -Anatole
>
>
>
> -----Original Message-----
> From: Romain Manni-Bucau [mailto:rmannibucau@gmail.com]
> Sent: Montag, 1. Dezember 2014 09:43
> To: dev@tamaya.incubator.apache.org
> Subject: Re: CharSequence instead of String
>
> think we should support String so CharSequence would be another
> supported type. Main reason is valueOf(String) or fromString(String)
> is common in several specs.
>
> No issues supporting both but not supporting string would be quite
> uncommon for me, wdyt?
>
>
> Romain Manni-Bucau
> @rmannibucau
> http://www.tomitribe.com
> http://rmannibucau.wordpress.com
> https://github.com/rmannibucau
>
>
> 2014-12-01 9:12 GMT+01:00 Oliver B. Fischer <o....@swe-blog.net>:
>> Hi,
>>
>> after our dicussing the data type conversion topic I got the impression what
>> we should use
>>
>> 1. CharSequence as basic data type
>>
>> Is this true for all of us?
>>
>> How does it affect our API? Should we use CharSequence consistently in our
>> API?
>>
>> wdyt?
>>
>> Oliver
>>
>> --
>> N Oliver B. Fischer
>> A Schönhauser Allee 64, 10437 Berlin, Deutschland/Germany
>> P +49 30 44793251
>> M +49 178 7903538
>> E o.b.fischer@swe-blog.net
>> S oliver.b.fischer
>> J oliver.b.fischer@jabber.org
>> X http://xing.to/obf
>>

-- 
N Oliver B. Fischer
A Schönhauser Allee 64, 10437 Berlin, Deutschland/Germany
P +49 30 44793251
M +49 178 7903538
E o.b.fischer@swe-blog.net
S oliver.b.fischer
J oliver.b.fischer@jabber.org
X http://xing.to/obf


RE: CharSequence instead of String

Posted by "Tresch, Anatole " <an...@credit-suisse.com>.
+1 String support is mandatory. CharSequence for me, often is a good thing, but sometimes also is simply not needed. Typically it is very useful, where you have some kind of String handling in place, as it is typical for parsing or formatting. In cases where you typically pass constant keys only, I see only limited advantages (or even disadvantages by bloating the API, creating unnecessary Strings ...).

So I would ask for concrete proposals where to add it, so we can focus discussion on the concrete cases ;)

-Anatole



-----Original Message-----
From: Romain Manni-Bucau [mailto:rmannibucau@gmail.com] 
Sent: Montag, 1. Dezember 2014 09:43
To: dev@tamaya.incubator.apache.org
Subject: Re: CharSequence instead of String

think we should support String so CharSequence would be another
supported type. Main reason is valueOf(String) or fromString(String)
is common in several specs.

No issues supporting both but not supporting string would be quite
uncommon for me, wdyt?


Romain Manni-Bucau
@rmannibucau
http://www.tomitribe.com
http://rmannibucau.wordpress.com
https://github.com/rmannibucau


2014-12-01 9:12 GMT+01:00 Oliver B. Fischer <o....@swe-blog.net>:
> Hi,
>
> after our dicussing the data type conversion topic I got the impression what
> we should use
>
> 1. CharSequence as basic data type
>
> Is this true for all of us?
>
> How does it affect our API? Should we use CharSequence consistently in our
> API?
>
> wdyt?
>
> Oliver
>
> --
> N Oliver B. Fischer
> A Schönhauser Allee 64, 10437 Berlin, Deutschland/Germany
> P +49 30 44793251
> M +49 178 7903538
> E o.b.fischer@swe-blog.net
> S oliver.b.fischer
> J oliver.b.fischer@jabber.org
> X http://xing.to/obf
>

Re: CharSequence instead of String

Posted by Romain Manni-Bucau <rm...@gmail.com>.
think we should support String so CharSequence would be another
supported type. Main reason is valueOf(String) or fromString(String)
is common in several specs.

No issues supporting both but not supporting string would be quite
uncommon for me, wdyt?


Romain Manni-Bucau
@rmannibucau
http://www.tomitribe.com
http://rmannibucau.wordpress.com
https://github.com/rmannibucau


2014-12-01 9:12 GMT+01:00 Oliver B. Fischer <o....@swe-blog.net>:
> Hi,
>
> after our dicussing the data type conversion topic I got the impression what
> we should use
>
> 1. CharSequence as basic data type
>
> Is this true for all of us?
>
> How does it affect our API? Should we use CharSequence consistently in our
> API?
>
> wdyt?
>
> Oliver
>
> --
> N Oliver B. Fischer
> A Schönhauser Allee 64, 10437 Berlin, Deutschland/Germany
> P +49 30 44793251
> M +49 178 7903538
> E o.b.fischer@swe-blog.net
> S oliver.b.fischer
> J oliver.b.fischer@jabber.org
> X http://xing.to/obf
>