Saturday, March 29, 2008

Method references (Implementation Issue)

Method references (Implementation Issue)

Each method reference is transformed to a closure:

  // Math#sqrt(double) will be transformed to { double d => Math.sqrt(d) }
  { double => double } sqrt = Math#sqrt(double);
  

Instance method references are transformed in a similar way.

  Circle c = new Circle();
  { => void } p = c#draw();  // the same as { => c.draw(); }
  
  { Circle => void } p = Circle#draw();  // { Circle c => c.draw(); }
  

Let us have a look at another example. We declare class Box:

  public class Box<T> {
    T v;
    public Box(T v) {
      this.v = v;
    }
    public T getValue() {
      return v;
    }
    public void print() {
      System.out.println("Box: " + v);
    }
  }
  

and refer to the print method:

  // Box#print() will be transformed to { Box<Integer> box => box.print(); }
  { Box<Integer> => void } p = Box#print();
  

Reference to a generic method will be replaced by a closure as follows:

  public class Generic {
    public static <T> Box<T> copy(Box<T> b) {
        return new Box<T>(b.getValue());
    }
  }
  
  // Generic#copy(Box<Integer>) will be transformed to 
  // { Box<Integer> box => Generic.copy(box) }
  { Box<Integer> => Box<Integer> } boxCopy = Generic#copy(Box<Integer>);
  

I do not want closures in Java because they are not simple.
This argument is wrong. We should always weigh all pros and cons. Closures are not simple. But is software development in Java simple? What should I know to be capable to develop software in Java? Knowledge of the Java programming language is clearly not enough. One should also know some Java technologies and frameworks. And are they simple? Are JPA, EJB, JAX-WS, Hibernate, or Spring (to name a few) simple? Apparently no, so it does not make sense to reject closures just for this reason.

18 comments:

Luc Duponcheel said...

I would even want to go further than your statement about closures

IMHO there is this difference between

simple versus complex
easy versus difficult

By the way: things that are complex may appear to be difficult

in the context of programming

simple/complex is mainly a syntactic thing
(syntax is about the form of programming language constructs)

easy/difficult is mainly a semantic thing
(semantics is about the meaning of programming language constructs)

q1: are closures complex?
a1: they are simpler that all other Java syntax that has the same semantics

q2: are closures difficult?
a2: well, that depends! I do not want to sound offensive to those who find them difficult, but the answer to this question depends on the capability of us, human beings, to understand a certain concept. Closures are certainly not making the concept more difficult than needed (because of (a1))


Go on doing this tutorial thing, Zdenek!

Luc

Anonymous said...

Great stuff, thanks a lot!

Anonymous said...

Hey, I don't know a better place to ask, is there a place where people put their closure powered code? Is there a place where I can put mine?

Anonymous said...

Well now there is. I'd be glad if you'd pass by and leave comments.

Zdeněk Troníček said...

Hi felix,

sure, you can post a closure code here. Another place is perhaps Neal Gafter's blog.

Viagra Asli Di Medan said...

Thank you for sharing in this article
I can learn a lot and could also be a reference
I hope to read the next your article updates
Vimax Asli
Ciri-ciri Vimax Asli Canada
Vimax Original
Obat Pembesar Penis Herbal
Agen Vimax Original
Vimax
Vimax Asli Canada
Vimax Asli Canada Di Medan
Vimax Original
Vimax Asli Canada Izon
Vimax Obat Pembesar Penis
Vimax Asli
Agen Vimax Original
Obat Pembesar Penis Herbal
Ciri Vimax Asli Canada
Ciri Vimax Asli Canada
Vagina Getar Goyang Alat Bantu Sex Pria
Vimax
Obat Pembesar Penis NeoSize
Alat Pembesar Penis Terbaru Pro Extender
Celana Pembesar Penis Celana Dalam Vakoou
Vakum Pembesar Penis
Vigrx Plus Obat Pembesar Penis
KLG Pill Pembesar Penis Terbaik
Obat Perangsang Wanita Terbaik Blue Wizard Cair
Obat Perangsang Permen Cinta sex Love
Potenzol Obat Perangsang Wanita Terbaik
Obat Kuat Levitra
Viagra USA Asli Obat Sex
Cialis Obat Sex Pria Dewasa
Vakum Pembesar Payudara Permanen
Selaput Dara Buatan
Penis Getar Goyang Mutiara Alat Bantu Sex

Radley Co Tad said...

Very much useful article. Kindly keep blogging

Java Training in Chennai

Java Online Training India

Diya shree said...

Thank you for sharing your article. Great efforts put it to find the list of articles which is very useful to know, Definitely will share the same to other forums.
data science course in chennai quora | data science course fees in chennai | data science course in chennai velachery | data science course in chennai omr

Anjali Siva said...

The given information was excellent and useful. This is one of the excellent blog, I have come across. Do share more.
Data Science Training in Chennai
Data Analytics Training in Chennai
Data Science Certification in Chennai
Data Science Training in Velachery
R Training in Chennai
R Programming Training in Chennai
Machine Learning Training in Chennai
Machine Learning institute in Chennai
Data Science Course in Chennai

Rajesh said...

Nice information, want to know about Selenium Training In Chennai
Selenium Training In Chennai
Data Science Course In Chennai
Protractor Training in Chennai
jmeter training in chennai
Rpa Training Chennai
Rpa Course Chennai
Selenium Training institute In Chennai
Python Training In Chennai

Rajesh said...

Rpa Training in Chennai
Rpa Course in Chennai
Blue prism training in Chennai

Rajesh said...

Data Science Training In Chennai
Data Science Course In Chennai
Data Science Course In Chennai

Rajesh said...

Nice information, want to know about Selenium Training In Chennai
Selenium Training In Chennai
Data Science Course In Chennai
Protractor Training in Chennai
jmeter training in chennai
Rpa Training Chennai
Rpa Course Chennai
Selenium Training institute In Chennai
Python Training In Chennai

klinik aborsi said...

Jual Obat Aborsi Asli | Obat Cytotec Asli | 082241083319
jual obat aborsi pills cytotec asli manjur untuk menggugurkan kandungan usia 1 - 6 bulan gugur tuntas.CYTOTEC OBAT ASLI sangat efektif mengatasi TELAT DATANG BULANdan menjadikan anda gagal hamil , CYTOTEC adalah OBAT ABORSI 3 JAM BERHASIL GUGUR TUNTAS dengan kwalitas terbaik produk asli pfizer nomor 1 di dunia medis
JUAL OBAT ABORSI DI SUMEDANG
JUAL OBAT ABORSI DI TASIKMALAYA
JUAL OBAT ABORSI DI BANJAR
JUAL OBAT ABORSI DI DEPOK
JUAL OBAT ABORSI DI PALEMBANG



surya said...

Really it was an awesome blog...very interesting to read..You have provided an nice information.
Angular JS Training in Chennai | Certification | Online Training Course | Angular JS Training in Bangalore | Certification | Online Training Course | Angular JS Training in Hyderabad | Certification | Online Training Course | Angular JS Training in Coimbatore | Certification | Online Training Course | Angular JS Training | Certification | Angular JS Online Training Course

Plumbing & HVAC Services San Diego said...

Compre documentos en línea, documentos originales y registrados.
Acerca de Permisodeespana, algunos dicen que somos los solucionadores de problemas, mientras que otros se refieren a nosotros como vendedores de soluciones. Contamos con cientos de clientes satisfechos a nivel mundial. Hacemos documentos falsos autorizados y aprobados como Permiso de Residencia Español, DNI, Pasaporte Español y Licencia de Conducir Española. Somos los fabricantes y proveedores de primer nivel de estos documentos, reconocidos a nivel mundial.

Comprar permiso de residencia,
permiso de residenciareal y falso en línea,
Compre licencia de conducir en línea,
Compre una licencia de conducir española falsa en línea,
Comprar tarjeta de identificación,
Licencia de conducir real y falsa,
Compre pasaporte real en línea,

Visit Here fpr more information. :- https://permisodeespana.com/licencia-de-conducir-espanola/
Address: 56 Guild Street, London, EC4A 3WU (UK)
Email: contact@permisodeespana.com
WhatsApp: +443455280186

Links For You said...

obviously a satisfying computation. i've confirmation this surprising broadcast. much thanks to you for sharing suggestion generally it. I in truth further to that. much obliged accurately parcel to your assemble. Microsoft Office Product Key Free

crackdj.com

UnoGeeks said...

Thank you for sharing such a nice and interesting blog and really very helpful article.
Oracle Recruiting Cloud Training