Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #14037
| Path | csiph.com!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail |
|---|---|
| From | Lew <noone@lewscanon.com> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: this |
| Date | Sun, 29 Apr 2012 12:51:08 -0700 |
| Organization | albasani.net |
| Lines | 41 |
| Message-ID | <jnk63c$e5j$1@news.albasani.net> (permalink) |
| References | <6cab49af-72f5-4bb4-87f8-7eb2e6330b05@t23g2000yqd.googlegroups.com> <jnjja8$bcc$1@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.albasani.net nG2mmABpAMGwKcp4IgWijg4aaqHChV4i060Q0/SBn4iW3IFmHoWCPLXkXbUdI3Tmw3R/ro0jLuCIn945bNJo9xH0OrFBWgY+AXLxmPoafVjC6pwXm2n5Pq7bYNjGt4SS |
| NNTP-Posting-Date | Sun, 29 Apr 2012 19:51:08 +0000 (UTC) |
| Injection-Info | news.albasani.net; logging-data="in7Mjds4BVQfdnZb7C+EsoxQtfBOgwz4kZRh3LSTZspXf8z8EN+IFVkrH3Pw/H8nlM1YElJYooNgXiuU07n+HlpIZGjsJTBOSSRp6oE56pHrKQ/RN2+NDZPIc6p8Y8h/"; mail-complaints-to="abuse@albasani.net" |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120329 Thunderbird/11.0.1 |
| In-Reply-To | <jnjja8$bcc$1@dont-email.me> |
| Cancel-Lock | sha1:EPP2Xo/H/fxqPlviPPt0koS76o0= |
| Xref | csiph.com comp.lang.java.programmer:14037 |
Show key headers only | View raw
Tsukino Usagi wrote:
...
> One of the more interesting usages of "this" remains passing a reference to an
> object versus defining scope. It can be used to create a way to pass a
> function as an argument. For example, if we have a well-known function name
Excellent example for several reasons.
> encapsulated as a class (think "Thread", "Runnable", or "Callable"):
>
> class Callable { callme(Object o) { /* code here */ } }
Quibble: This should be an interface, not a class, and we should declare
pedagogical examples 'public', and most certainly the method should be:
/* not to be confused with
<http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Callable.html>
*/
public interface Callable<T>
{
void callMe(T client);
}
> class Println extends Callable { callme(Object o) { println(o); } }
public class Println implements Callable<Object>
{
@Override
public void callMe(Object client)
{
System.out.println(client);
}
}
The pattern of single abstract method (SAM) interfaces is so prevalent and
useful that Java will introduce a sort-of functional syntax for it in Java 8.
--
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
this mojde <mojdeyazdi@gmail.com> - 2012-04-28 05:33 -0700
Re: this Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2012-04-28 11:06 -0300
Re: this "John B. Matthews" <nospam@nospam.invalid> - 2012-04-28 10:46 -0400
Re: this Roedy Green <see_website@mindprod.com.invalid> - 2012-04-28 08:01 -0700
Re: this Tsukino Usagi <usagi@tsukino.ca> - 2012-04-29 23:30 +0900
Re: this Lew <noone@lewscanon.com> - 2012-04-29 12:51 -0700
csiph-web