You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Paul Benedict <pb...@apache.org> on 2009/11/26 06:16:58 UTC

[lang 3] static or dynamic type checks?

If we want to implement LANG-508 (Validate: add message parameter
construction via elllipsis notation to speed up processing), I am
really concerned with the many overloaded versions of #validIndex()
and #notEmpty() that solely differ by static argument type:
Collection, Object, Object[], CharSequence, etc.

Because var-args instantiate a new Object[], it won't be possible to
easily create one-argument optimized overloaded versions to prevent
the creation. Such as:
public static <T> T[] notEmpty(Object array, String message, Object var1);
public static <T> T[] notEmpty(Object array, String message, Object
var1, Object var2);
public static <T> T[] notEmpty(Object array, String message, Object
var1, Object var2, Object var3);
public static <T> T[] notEmpty(Object array, String message, Object
var1, Object var2, Object var3, Object... vars);

I am following the good advice on Joshua Bloch on this one. It's item
#42 in his Effective Java book.

I want to eliminate the overloaded versions by type and check those
types using instanceof instead. Thoughts?

Paul

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [lang 3] static or dynamic type checks?

Posted by Henri Yandell <fl...@gmail.com>.
What are the pros and cons?

On Wed, Nov 25, 2009 at 9:16 PM, Paul Benedict <pb...@apache.org> wrote:
> If we want to implement LANG-508 (Validate: add message parameter
> construction via elllipsis notation to speed up processing), I am
> really concerned with the many overloaded versions of #validIndex()
> and #notEmpty() that solely differ by static argument type:
> Collection, Object, Object[], CharSequence, etc.
>
> Because var-args instantiate a new Object[], it won't be possible to
> easily create one-argument optimized overloaded versions to prevent
> the creation. Such as:
> public static <T> T[] notEmpty(Object array, String message, Object var1);
> public static <T> T[] notEmpty(Object array, String message, Object
> var1, Object var2);
> public static <T> T[] notEmpty(Object array, String message, Object
> var1, Object var2, Object var3);
> public static <T> T[] notEmpty(Object array, String message, Object
> var1, Object var2, Object var3, Object... vars);
>
> I am following the good advice on Joshua Bloch on this one. It's item
> #42 in his Effective Java book.
>
> I want to eliminate the overloaded versions by type and check those
> types using instanceof instead. Thoughts?
>
> Paul
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [lang 3] static or dynamic type checks?

Posted by Stephen Colebourne <sc...@joda.org>.
I'm unconvinced by this change overall. It feels like a bit of a
diversion from the original purpose of the class. I think it
complicates greatly what should be a really simple, no-brainer, class.

I could live with a one arg addition, but want to avoid varargs and primitives:
 public static <T> T[] notEmpty(Object array, String message, Object var);

Stephen


2009/11/26 Paul Benedict <pb...@apache.org>:
> If we want to implement LANG-508 (Validate: add message parameter
> construction via elllipsis notation to speed up processing), I am
> really concerned with the many overloaded versions of #validIndex()
> and #notEmpty() that solely differ by static argument type:
> Collection, Object, Object[], CharSequence, etc.
>
> Because var-args instantiate a new Object[], it won't be possible to
> easily create one-argument optimized overloaded versions to prevent
> the creation. Such as:
> public static <T> T[] notEmpty(Object array, String message, Object var1);
> public static <T> T[] notEmpty(Object array, String message, Object
> var1, Object var2);
> public static <T> T[] notEmpty(Object array, String message, Object
> var1, Object var2, Object var3);
> public static <T> T[] notEmpty(Object array, String message, Object
> var1, Object var2, Object var3, Object... vars);
>
> I am following the good advice on Joshua Bloch on this one. It's item
> #42 in his Effective Java book.
>
> I want to eliminate the overloaded versions by type and check those
> types using instanceof instead. Thoughts?
>
> Paul
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [lang 3] static or dynamic type checks?

Posted by Paul Benedict <pb...@apache.org>.
James,

I would typically agree about the bad design part except for the usage
of valdiation. Here, all we want to do is validate an object, as you
said, and the public API does not take advantage of the static type
(such as different parameters). It's better for introspection to
occur, IMO.

Paul

On Fri, Nov 27, 2009 at 6:47 AM, James Carman
<ja...@carmanconsulting.com> wrote:
> Are we going to keep the 2,3,4-arg versions?  We have to have one that
> accepts Object anyway, so I guess it does keep the API a bit cleaner
> to not clutter it with a Map, Collection, etc. version.  I really
> don't like instanceof in code, though.  It just screams bad design.
> Usually it means that you aren't thinking in an object-oriented
> fashion.
>
> On Fri, Nov 27, 2009 at 12:08 AM, Paul Benedict <pb...@apache.org> wrote:
>> I think we should reduce the overloading and just accept Object. From the
>> runtime type, we can determine how to do further checks. Then, we can nicely
>> implement 1 args, 2, args, ... and finally var-args overloads.
>>
>> Paul
>>
>> On 11/26/2009 10:49 PM, James Carman wrote:
>>>
>>> So, what you're concerned with is the first parameter (the "thing" we
>>> want to check, which we do so by reflection)?  Why do we need to
>>> change its type?
>>>
>>> On Thu, Nov 26, 2009 at 10:42 PM, Paul Benedict<pb...@apache.org>
>>>  wrote:
>>>
>>>>
>>>> James,
>>>>
>>>> Yes. I want to also eliminate the static types of all the overloaded
>>>> methods. We don't need a version for maps, one for char sets, one for
>>>> objects, one for collections, etc. We can do all those checks
>>>> dynamically.
>>>>
>>>> This was my point of my original email. What are your thoughts on it?
>>>>
>>>> Paul
>>>>
>>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [lang 3] static or dynamic type checks?

Posted by James Carman <ja...@carmanconsulting.com>.
Are we going to keep the 2,3,4-arg versions?  We have to have one that
accepts Object anyway, so I guess it does keep the API a bit cleaner
to not clutter it with a Map, Collection, etc. version.  I really
don't like instanceof in code, though.  It just screams bad design.
Usually it means that you aren't thinking in an object-oriented
fashion.

On Fri, Nov 27, 2009 at 12:08 AM, Paul Benedict <pb...@apache.org> wrote:
> I think we should reduce the overloading and just accept Object. From the
> runtime type, we can determine how to do further checks. Then, we can nicely
> implement 1 args, 2, args, ... and finally var-args overloads.
>
> Paul
>
> On 11/26/2009 10:49 PM, James Carman wrote:
>>
>> So, what you're concerned with is the first parameter (the "thing" we
>> want to check, which we do so by reflection)?  Why do we need to
>> change its type?
>>
>> On Thu, Nov 26, 2009 at 10:42 PM, Paul Benedict<pb...@apache.org>
>>  wrote:
>>
>>>
>>> James,
>>>
>>> Yes. I want to also eliminate the static types of all the overloaded
>>> methods. We don't need a version for maps, one for char sets, one for
>>> objects, one for collections, etc. We can do all those checks
>>> dynamically.
>>>
>>> This was my point of my original email. What are your thoughts on it?
>>>
>>> Paul
>>>
>>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [lang 3] static or dynamic type checks?

Posted by Paul Benedict <pb...@apache.org>.
I think we should reduce the overloading and just accept Object. From 
the runtime type, we can determine how to do further checks. Then, we 
can nicely implement 1 args, 2, args, ... and finally var-args overloads.

Paul

On 11/26/2009 10:49 PM, James Carman wrote:
> So, what you're concerned with is the first parameter (the "thing" we
> want to check, which we do so by reflection)?  Why do we need to
> change its type?
>
> On Thu, Nov 26, 2009 at 10:42 PM, Paul Benedict<pb...@apache.org>  wrote:
>    
>> James,
>>
>> Yes. I want to also eliminate the static types of all the overloaded
>> methods. We don't need a version for maps, one for char sets, one for
>> objects, one for collections, etc. We can do all those checks dynamically.
>>
>> This was my point of my original email. What are your thoughts on it?
>>
>> Paul
>>
>>      


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [lang 3] static or dynamic type checks?

Posted by James Carman <ja...@carmanconsulting.com>.
So, what you're concerned with is the first parameter (the "thing" we
want to check, which we do so by reflection)?  Why do we need to
change its type?

On Thu, Nov 26, 2009 at 10:42 PM, Paul Benedict <pb...@apache.org> wrote:
> James,
>
> Yes. I want to also eliminate the static types of all the overloaded
> methods. We don't need a version for maps, one for char sets, one for
> objects, one for collections, etc. We can do all those checks dynamically.
>
> This was my point of my original email. What are your thoughts on it?
>
> Paul
>
> On 11/26/2009 8:50 PM, James Carman wrote:
>>
>> I understand that.  My point is that if you can create two, overloaded
>> methods (which I've shown you can do), one with one single argument
>> and one with var-args, then you can avoid the Object[] instantiation
>> in the single-argument case.
>>
>> On Thu, Nov 26, 2009 at 9:42 PM, Paul Benedict<pb...@apache.org>
>>  wrote:
>>>
>>> James,
>>>
>>> The compiler instantiates the Object[] every time because that's how
>>> the ellipsis notation is translated.
>>>
>>> Paul
>>>
>>> On Thu, Nov 26, 2009 at 7:38 PM, James Carman
>>> <ja...@carmanconsulting.com>  wrote:
>>>>
>>>> Yes, but if the check passes, there's no need to create the Object[]
>>>> for single-argument method invocations.
>>>>
>>>> On Thu, Nov 26, 2009 at 10:59 AM, Paul Benedict<pb...@apache.org>
>>>>  wrote:
>>>>>
>>>>> The purpose of var-args, at least from my vantage, is to produce
>>>>> detail messages that are used by java.lang.String.format.
>>>>>
>>>>> Paul
>>>>>
>>>>> On Thu, Nov 26, 2009 at 7:11 AM, James Carman
>>>>> <ja...@carmanconsulting.com>  wrote:
>>>>>>
>>>>>> I just wrote a class that included...
>>>>>>
>>>>>>    public static<T>  T someMethod(T val)
>>>>>>    {
>>>>>>        System.out.println("Single value method!");
>>>>>>        return val;
>>>>>>    }
>>>>>>
>>>>>>    public static<T>  T[] someMethod(T... values)
>>>>>>    {
>>>>>>        System.out.println("Multi-value method.");
>>>>>>        return values;
>>>>>>    }
>>>>>>
>>>>>>    public static void main(String[] args)
>>>>>>    {
>>>>>>        someMethod("Hello");
>>>>>>        someMethod("Hello", "World");
>>>>>>    }
>>>>>>
>>>>>> When I ran it, it printed:
>>>>>>
>>>>>> Single value method!
>>>>>> Multi-value method.
>>>>>>
>>>>>> So, what's the big deal?  Create a single-value method and create a
>>>>>> multi-value method.  I must be missing something in this discussion.
>>>>>>
>>>>>> On Thu, Nov 26, 2009 at 12:16 AM, Paul Benedict<pb...@apache.org>
>>>>>>  wrote:
>>>>>>>
>>>>>>> If we want to implement LANG-508 (Validate: add message parameter
>>>>>>> construction via elllipsis notation to speed up processing), I am
>>>>>>> really concerned with the many overloaded versions of #validIndex()
>>>>>>> and #notEmpty() that solely differ by static argument type:
>>>>>>> Collection, Object, Object[], CharSequence, etc.
>>>>>>>
>>>>>>> Because var-args instantiate a new Object[], it won't be possible to
>>>>>>> easily create one-argument optimized overloaded versions to prevent
>>>>>>> the creation. Such as:
>>>>>>> public static<T>  T[] notEmpty(Object array, String message, Object
>>>>>>> var1);
>>>>>>> public static<T>  T[] notEmpty(Object array, String message, Object
>>>>>>> var1, Object var2);
>>>>>>> public static<T>  T[] notEmpty(Object array, String message, Object
>>>>>>> var1, Object var2, Object var3);
>>>>>>> public static<T>  T[] notEmpty(Object array, String message, Object
>>>>>>> var1, Object var2, Object var3, Object... vars);
>>>>>>>
>>>>>>> I am following the good advice on Joshua Bloch on this one. It's item
>>>>>>> #42 in his Effective Java book.
>>>>>>>
>>>>>>> I want to eliminate the overloaded versions by type and check those
>>>>>>> types using instanceof instead. Thoughts?
>>>>>>>
>>>>>>> Paul
>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>>>>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>>>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>>>>
>>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>>>
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [lang 3] static or dynamic type checks?

Posted by Paul Benedict <pb...@apache.org>.
James,

Yes. I want to also eliminate the static types of all the overloaded 
methods. We don't need a version for maps, one for char sets, one for 
objects, one for collections, etc. We can do all those checks dynamically.

This was my point of my original email. What are your thoughts on it?

Paul

On 11/26/2009 8:50 PM, James Carman wrote:
> I understand that.  My point is that if you can create two, overloaded
> methods (which I've shown you can do), one with one single argument
> and one with var-args, then you can avoid the Object[] instantiation
> in the single-argument case.
>
> On Thu, Nov 26, 2009 at 9:42 PM, Paul Benedict<pb...@apache.org>  wrote:
>> James,
>>
>> The compiler instantiates the Object[] every time because that's how
>> the ellipsis notation is translated.
>>
>> Paul
>>
>> On Thu, Nov 26, 2009 at 7:38 PM, James Carman
>> <ja...@carmanconsulting.com>  wrote:
>>> Yes, but if the check passes, there's no need to create the Object[]
>>> for single-argument method invocations.
>>>
>>> On Thu, Nov 26, 2009 at 10:59 AM, Paul Benedict<pb...@apache.org>  wrote:
>>>> The purpose of var-args, at least from my vantage, is to produce
>>>> detail messages that are used by java.lang.String.format.
>>>>
>>>> Paul
>>>>
>>>> On Thu, Nov 26, 2009 at 7:11 AM, James Carman
>>>> <ja...@carmanconsulting.com>  wrote:
>>>>> I just wrote a class that included...
>>>>>
>>>>>     public static<T>  T someMethod(T val)
>>>>>     {
>>>>>         System.out.println("Single value method!");
>>>>>         return val;
>>>>>     }
>>>>>
>>>>>     public static<T>  T[] someMethod(T... values)
>>>>>     {
>>>>>         System.out.println("Multi-value method.");
>>>>>         return values;
>>>>>     }
>>>>>
>>>>>     public static void main(String[] args)
>>>>>     {
>>>>>         someMethod("Hello");
>>>>>         someMethod("Hello", "World");
>>>>>     }
>>>>>
>>>>> When I ran it, it printed:
>>>>>
>>>>> Single value method!
>>>>> Multi-value method.
>>>>>
>>>>> So, what's the big deal?  Create a single-value method and create a
>>>>> multi-value method.  I must be missing something in this discussion.
>>>>>
>>>>> On Thu, Nov 26, 2009 at 12:16 AM, Paul Benedict<pb...@apache.org>  wrote:
>>>>>> If we want to implement LANG-508 (Validate: add message parameter
>>>>>> construction via elllipsis notation to speed up processing), I am
>>>>>> really concerned with the many overloaded versions of #validIndex()
>>>>>> and #notEmpty() that solely differ by static argument type:
>>>>>> Collection, Object, Object[], CharSequence, etc.
>>>>>>
>>>>>> Because var-args instantiate a new Object[], it won't be possible to
>>>>>> easily create one-argument optimized overloaded versions to prevent
>>>>>> the creation. Such as:
>>>>>> public static<T>  T[] notEmpty(Object array, String message, Object var1);
>>>>>> public static<T>  T[] notEmpty(Object array, String message, Object
>>>>>> var1, Object var2);
>>>>>> public static<T>  T[] notEmpty(Object array, String message, Object
>>>>>> var1, Object var2, Object var3);
>>>>>> public static<T>  T[] notEmpty(Object array, String message, Object
>>>>>> var1, Object var2, Object var3, Object... vars);
>>>>>>
>>>>>> I am following the good advice on Joshua Bloch on this one. It's item
>>>>>> #42 in his Effective Java book.
>>>>>>
>>>>>> I want to eliminate the overloaded versions by type and check those
>>>>>> types using instanceof instead. Thoughts?
>>>>>>
>>>>>> Paul
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>>>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>>>>
>>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>>>
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [lang 3] static or dynamic type checks?

Posted by James Carman <ja...@carmanconsulting.com>.
I understand that.  My point is that if you can create two, overloaded
methods (which I've shown you can do), one with one single argument
and one with var-args, then you can avoid the Object[] instantiation
in the single-argument case.

On Thu, Nov 26, 2009 at 9:42 PM, Paul Benedict <pb...@apache.org> wrote:
> James,
>
> The compiler instantiates the Object[] every time because that's how
> the ellipsis notation is translated.
>
> Paul
>
> On Thu, Nov 26, 2009 at 7:38 PM, James Carman
> <ja...@carmanconsulting.com> wrote:
>> Yes, but if the check passes, there's no need to create the Object[]
>> for single-argument method invocations.
>>
>> On Thu, Nov 26, 2009 at 10:59 AM, Paul Benedict <pb...@apache.org> wrote:
>>> The purpose of var-args, at least from my vantage, is to produce
>>> detail messages that are used by java.lang.String.format.
>>>
>>> Paul
>>>
>>> On Thu, Nov 26, 2009 at 7:11 AM, James Carman
>>> <ja...@carmanconsulting.com> wrote:
>>>> I just wrote a class that included...
>>>>
>>>>    public static <T> T someMethod(T val)
>>>>    {
>>>>        System.out.println("Single value method!");
>>>>        return val;
>>>>    }
>>>>
>>>>    public static <T> T[] someMethod(T... values)
>>>>    {
>>>>        System.out.println("Multi-value method.");
>>>>        return values;
>>>>    }
>>>>
>>>>    public static void main(String[] args)
>>>>    {
>>>>        someMethod("Hello");
>>>>        someMethod("Hello", "World");
>>>>    }
>>>>
>>>> When I ran it, it printed:
>>>>
>>>> Single value method!
>>>> Multi-value method.
>>>>
>>>> So, what's the big deal?  Create a single-value method and create a
>>>> multi-value method.  I must be missing something in this discussion.
>>>>
>>>> On Thu, Nov 26, 2009 at 12:16 AM, Paul Benedict <pb...@apache.org> wrote:
>>>>> If we want to implement LANG-508 (Validate: add message parameter
>>>>> construction via elllipsis notation to speed up processing), I am
>>>>> really concerned with the many overloaded versions of #validIndex()
>>>>> and #notEmpty() that solely differ by static argument type:
>>>>> Collection, Object, Object[], CharSequence, etc.
>>>>>
>>>>> Because var-args instantiate a new Object[], it won't be possible to
>>>>> easily create one-argument optimized overloaded versions to prevent
>>>>> the creation. Such as:
>>>>> public static <T> T[] notEmpty(Object array, String message, Object var1);
>>>>> public static <T> T[] notEmpty(Object array, String message, Object
>>>>> var1, Object var2);
>>>>> public static <T> T[] notEmpty(Object array, String message, Object
>>>>> var1, Object var2, Object var3);
>>>>> public static <T> T[] notEmpty(Object array, String message, Object
>>>>> var1, Object var2, Object var3, Object... vars);
>>>>>
>>>>> I am following the good advice on Joshua Bloch on this one. It's item
>>>>> #42 in his Effective Java book.
>>>>>
>>>>> I want to eliminate the overloaded versions by type and check those
>>>>> types using instanceof instead. Thoughts?
>>>>>
>>>>> Paul
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>>>
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [lang 3] static or dynamic type checks?

Posted by Paul Benedict <pb...@apache.org>.
James,

The compiler instantiates the Object[] every time because that's how
the ellipsis notation is translated.

Paul

On Thu, Nov 26, 2009 at 7:38 PM, James Carman
<ja...@carmanconsulting.com> wrote:
> Yes, but if the check passes, there's no need to create the Object[]
> for single-argument method invocations.
>
> On Thu, Nov 26, 2009 at 10:59 AM, Paul Benedict <pb...@apache.org> wrote:
>> The purpose of var-args, at least from my vantage, is to produce
>> detail messages that are used by java.lang.String.format.
>>
>> Paul
>>
>> On Thu, Nov 26, 2009 at 7:11 AM, James Carman
>> <ja...@carmanconsulting.com> wrote:
>>> I just wrote a class that included...
>>>
>>>    public static <T> T someMethod(T val)
>>>    {
>>>        System.out.println("Single value method!");
>>>        return val;
>>>    }
>>>
>>>    public static <T> T[] someMethod(T... values)
>>>    {
>>>        System.out.println("Multi-value method.");
>>>        return values;
>>>    }
>>>
>>>    public static void main(String[] args)
>>>    {
>>>        someMethod("Hello");
>>>        someMethod("Hello", "World");
>>>    }
>>>
>>> When I ran it, it printed:
>>>
>>> Single value method!
>>> Multi-value method.
>>>
>>> So, what's the big deal?  Create a single-value method and create a
>>> multi-value method.  I must be missing something in this discussion.
>>>
>>> On Thu, Nov 26, 2009 at 12:16 AM, Paul Benedict <pb...@apache.org> wrote:
>>>> If we want to implement LANG-508 (Validate: add message parameter
>>>> construction via elllipsis notation to speed up processing), I am
>>>> really concerned with the many overloaded versions of #validIndex()
>>>> and #notEmpty() that solely differ by static argument type:
>>>> Collection, Object, Object[], CharSequence, etc.
>>>>
>>>> Because var-args instantiate a new Object[], it won't be possible to
>>>> easily create one-argument optimized overloaded versions to prevent
>>>> the creation. Such as:
>>>> public static <T> T[] notEmpty(Object array, String message, Object var1);
>>>> public static <T> T[] notEmpty(Object array, String message, Object
>>>> var1, Object var2);
>>>> public static <T> T[] notEmpty(Object array, String message, Object
>>>> var1, Object var2, Object var3);
>>>> public static <T> T[] notEmpty(Object array, String message, Object
>>>> var1, Object var2, Object var3, Object... vars);
>>>>
>>>> I am following the good advice on Joshua Bloch on this one. It's item
>>>> #42 in his Effective Java book.
>>>>
>>>> I want to eliminate the overloaded versions by type and check those
>>>> types using instanceof instead. Thoughts?
>>>>
>>>> Paul
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [lang 3] static or dynamic type checks?

Posted by James Carman <ja...@carmanconsulting.com>.
Yes, but if the check passes, there's no need to create the Object[]
for single-argument method invocations.

On Thu, Nov 26, 2009 at 10:59 AM, Paul Benedict <pb...@apache.org> wrote:
> The purpose of var-args, at least from my vantage, is to produce
> detail messages that are used by java.lang.String.format.
>
> Paul
>
> On Thu, Nov 26, 2009 at 7:11 AM, James Carman
> <ja...@carmanconsulting.com> wrote:
>> I just wrote a class that included...
>>
>>    public static <T> T someMethod(T val)
>>    {
>>        System.out.println("Single value method!");
>>        return val;
>>    }
>>
>>    public static <T> T[] someMethod(T... values)
>>    {
>>        System.out.println("Multi-value method.");
>>        return values;
>>    }
>>
>>    public static void main(String[] args)
>>    {
>>        someMethod("Hello");
>>        someMethod("Hello", "World");
>>    }
>>
>> When I ran it, it printed:
>>
>> Single value method!
>> Multi-value method.
>>
>> So, what's the big deal?  Create a single-value method and create a
>> multi-value method.  I must be missing something in this discussion.
>>
>> On Thu, Nov 26, 2009 at 12:16 AM, Paul Benedict <pb...@apache.org> wrote:
>>> If we want to implement LANG-508 (Validate: add message parameter
>>> construction via elllipsis notation to speed up processing), I am
>>> really concerned with the many overloaded versions of #validIndex()
>>> and #notEmpty() that solely differ by static argument type:
>>> Collection, Object, Object[], CharSequence, etc.
>>>
>>> Because var-args instantiate a new Object[], it won't be possible to
>>> easily create one-argument optimized overloaded versions to prevent
>>> the creation. Such as:
>>> public static <T> T[] notEmpty(Object array, String message, Object var1);
>>> public static <T> T[] notEmpty(Object array, String message, Object
>>> var1, Object var2);
>>> public static <T> T[] notEmpty(Object array, String message, Object
>>> var1, Object var2, Object var3);
>>> public static <T> T[] notEmpty(Object array, String message, Object
>>> var1, Object var2, Object var3, Object... vars);
>>>
>>> I am following the good advice on Joshua Bloch on this one. It's item
>>> #42 in his Effective Java book.
>>>
>>> I want to eliminate the overloaded versions by type and check those
>>> types using instanceof instead. Thoughts?
>>>
>>> Paul
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [lang 3] static or dynamic type checks?

Posted by Paul Benedict <pb...@apache.org>.
The purpose of var-args, at least from my vantage, is to produce
detail messages that are used by java.lang.String.format.

Paul

On Thu, Nov 26, 2009 at 7:11 AM, James Carman
<ja...@carmanconsulting.com> wrote:
> I just wrote a class that included...
>
>    public static <T> T someMethod(T val)
>    {
>        System.out.println("Single value method!");
>        return val;
>    }
>
>    public static <T> T[] someMethod(T... values)
>    {
>        System.out.println("Multi-value method.");
>        return values;
>    }
>
>    public static void main(String[] args)
>    {
>        someMethod("Hello");
>        someMethod("Hello", "World");
>    }
>
> When I ran it, it printed:
>
> Single value method!
> Multi-value method.
>
> So, what's the big deal?  Create a single-value method and create a
> multi-value method.  I must be missing something in this discussion.
>
> On Thu, Nov 26, 2009 at 12:16 AM, Paul Benedict <pb...@apache.org> wrote:
>> If we want to implement LANG-508 (Validate: add message parameter
>> construction via elllipsis notation to speed up processing), I am
>> really concerned with the many overloaded versions of #validIndex()
>> and #notEmpty() that solely differ by static argument type:
>> Collection, Object, Object[], CharSequence, etc.
>>
>> Because var-args instantiate a new Object[], it won't be possible to
>> easily create one-argument optimized overloaded versions to prevent
>> the creation. Such as:
>> public static <T> T[] notEmpty(Object array, String message, Object var1);
>> public static <T> T[] notEmpty(Object array, String message, Object
>> var1, Object var2);
>> public static <T> T[] notEmpty(Object array, String message, Object
>> var1, Object var2, Object var3);
>> public static <T> T[] notEmpty(Object array, String message, Object
>> var1, Object var2, Object var3, Object... vars);
>>
>> I am following the good advice on Joshua Bloch on this one. It's item
>> #42 in his Effective Java book.
>>
>> I want to eliminate the overloaded versions by type and check those
>> types using instanceof instead. Thoughts?
>>
>> Paul
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [lang 3] static or dynamic type checks?

Posted by James Carman <ja...@carmanconsulting.com>.
I just wrote a class that included...

    public static <T> T someMethod(T val)
    {
        System.out.println("Single value method!");
        return val;
    }

    public static <T> T[] someMethod(T... values)
    {
        System.out.println("Multi-value method.");
        return values;
    }

    public static void main(String[] args)
    {
        someMethod("Hello");
        someMethod("Hello", "World");
    }

When I ran it, it printed:

Single value method!
Multi-value method.

So, what's the big deal?  Create a single-value method and create a
multi-value method.  I must be missing something in this discussion.

On Thu, Nov 26, 2009 at 12:16 AM, Paul Benedict <pb...@apache.org> wrote:
> If we want to implement LANG-508 (Validate: add message parameter
> construction via elllipsis notation to speed up processing), I am
> really concerned with the many overloaded versions of #validIndex()
> and #notEmpty() that solely differ by static argument type:
> Collection, Object, Object[], CharSequence, etc.
>
> Because var-args instantiate a new Object[], it won't be possible to
> easily create one-argument optimized overloaded versions to prevent
> the creation. Such as:
> public static <T> T[] notEmpty(Object array, String message, Object var1);
> public static <T> T[] notEmpty(Object array, String message, Object
> var1, Object var2);
> public static <T> T[] notEmpty(Object array, String message, Object
> var1, Object var2, Object var3);
> public static <T> T[] notEmpty(Object array, String message, Object
> var1, Object var2, Object var3, Object... vars);
>
> I am following the good advice on Joshua Bloch on this one. It's item
> #42 in his Effective Java book.
>
> I want to eliminate the overloaded versions by type and check those
> types using instanceof instead. Thoughts?
>
> Paul
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org