

Java 7 is adding dynamics - alrex021
http://www.baptiste-wicht.com/2010/04/java-7-more-dynamics/

======
ldh
While I'm really glad to see Java (the language) slowly evolving in a positive
direction, and it might bring me some joy at work if/when we switch to 7, I
can't imagine starting new projects in Java anymore if I had my way. Once
you've been exposed to the much nicer languages thriving on the JVM now, it's
hard to get excited about Java anymore.

I mean, I can't see this sort of thing as being very enjoyable to write all
the time.

    
    
      JComboBox combo = new JComboBox();
     
      MethodHandle handle = MethodHandles.lookup().findVirtual(JComboBox.class, "setModel", MethodType.make(void.class, ComboBoxModel.class));
     
      handle.invoke(combo, new CustomComboModel());

~~~
lukev
I think these dynamic features are actually intended for alternative JVM
languages.

If they're exposed via the Java reflection API at all, it's incidental to
their actual purpose.

~~~
jimbokun
I think they could also be useful in creating little DSLs, building parser
combinators, etc.

------
drunkpotato
Any word on tail-call optimization? Clojure's recur macro is pretty clever but
true compiler-level support for recursion would be nice.

~~~
Xurinos
I have not played with Clojure since it was introduced, but I have a question
about recur or tail recursion. Here is a trivial CL example (nontrivial might
be approaches to parsing):

    
    
      (defun find-nth-match (test from n)
        (if (= n 0)
            from
            (martial-n test (1+ from) n)))
      
      (defun martial-n (test from n)
        (find-nth-match test
                        from
                        (if (funcall test from) (1- n) n)))
      
      (find-nth-match #'evenp 1 5)  => 10
    
    

The idea is that tail recursion is not just recursing into the exact same
function you appear to be in. Is this available with current clojure? Can
recur help me somehow?

~~~
cgrand-net
No recur won't help you: it's only for self tail recursion, not for mutual
tail-recursive calls. You can use a trampoline or refactor your code.

------
unwind

        "There are three supported invocations modes :
        invokestatic, invokespecial, invokeinterface or 
        invokevirtual."
    

So ... Are there four, or is one very much like another?

~~~
Robin_Message
There are four:

static for static methods

special for constructors I think

virtual for class methods

interface for interface methods (since its harder to find where an interface
method is defined, its different to virtual)

