ACMNexus / google-collections

Automatically exported from code.google.com/p/google-collections
Apache License 2.0
0 stars 0 forks source link

Change Function.toStringFunction signature to be more Generic Friendly #146

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Change the existing toStringFunction from this signature:

static Function<Object,String> toStringFunction()

to this signature:

static <T> Function<T, String> toStringFunction()

this plays better with generics.  Code change would add a cast and an
unchecked warning:

  public static <T> Function<T, String> toStringFunction() {
    return (Function<T, String>) ToStringFunction.INSTANCE;
  }

Original issue reported on code.google.com by asfoun...@gmail.com on 13 Apr 2009 at 7:51

GoogleCodeExporter commented 8 years ago
The way it is is correct and plays fine with generics, and adding this type 
parameter
proved to be more trouble than it is worth.  Where are you having trouble?  Most
likely your trouble is caused not by our API but by another, which needs 
wildcards
but doesn't use them.  As a last resort, you can always cast the function like 
this:

  // I need to pretend this function is only capable of handling
  // Integers, for some odd reason
  @SuppressWarnings("unchecked")
  Function<Integer, String> castFunction = (Function) Functions.toStringFunction();

but again, you really should only very, very rarely need to do that.

Original comment by kevin...@gmail.com on 13 Apr 2009 at 8:15

GoogleCodeExporter commented 8 years ago

Original comment by kevin...@gmail.com on 5 May 2009 at 4:00

GoogleCodeExporter commented 8 years ago
Issue 301 has been merged into this issue.

Original comment by kevin...@gmail.com on 23 Nov 2009 at 9:22