Java 5.0 annotation in Scala?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Java 5.0 annotation in Scala?

Erol Akarsu-2
Is there any plan to have Java5.0-like annotation framework in Scala?

I believe Scala will be one of the best languages. It will be nice to have this
annotation feature in Scala. So, we can use Scala to build EJB3 beans.

Here is a small example of EJB3 bean with annotation.


@Stateful
@Remote(ShoppingCart.class)
public class ShoppingCartBean implements ShoppingCart, Serializable
{
   private HashMap<String, Integer> cart = new HashMap<String, Integer>();

   public void buy(String product, int quantity)
   {
      if (cart.containsKey(product))
      {
         int currq = cart.get(product);
         currq += quantity;
         cart.put(product, currq);
      }
      else
      {
         cart.put(product, quantity);
      }
   }

   public HashMap<String, Integer> getCartContents()
   {
      return cart;
   }

   @Remove
   public void checkout()
   {
      System.out.println("To be implemented");
   }
}



Thanks

Erol Akarsu

Reply | Threaded
Open this post in threaded view
|

Re: Java 5.0 annotation in Scala?

Burak Emir
Dear Erol,

thanks for your mail. Indeed we support annotations (attributes)
already. There is [serializable] and [cloneable].

for people interested in bean (not EJB just plain old Java beans)
development, there is also the attribute scala.reflect.BeanProperty,
which should automatically add setX and getX methods.

Unfortunately, I wanted to document and try that feature thoroughly as a
reaction to your mail, and then discovered that it's not working right
now http://scala-webapps.epfl.ch/bugtracking/bugs/displayItem.do?id=579 
but it should get fixed in a very short time.

There is in principle nothing that prevents us from going all the way to
EJB and what not support, because attributes can be user defined classes
-- but it is not a priority for us. I guess if people need some support
from the compiler for creating EJB stuff or the -- more recent,
dotnet-inspired -- webmethod attributes in the upcoming Java Servlet
spec v2.5 , then we could talk about getting a standardized interface
for that... it should not be too hard, given the modular extensible
nature of our compiler

cheers,
Burak


Erol Akarsu wrote:

>Is there any plan to have Java5.0-like annotation framework in Scala?
>
>I believe Scala will be one of the best languages. It will be nice to have this
>annotation feature in Scala. So, we can use Scala to build EJB3 beans.
>
>Here is a small example of EJB3 bean with annotation.
>
>
>@Stateful
>@Remote(ShoppingCart.class)
>public class ShoppingCartBean implements ShoppingCart, Serializable
>{
>   private HashMap<String, Integer> cart = new HashMap<String, Integer>();
>
>   public void buy(String product, int quantity)
>   {
>      if (cart.containsKey(product))
>      {
>         int currq = cart.get(product);
>         currq += quantity;
>         cart.put(product, currq);
>      }
>      else
>      {
>         cart.put(product, quantity);
>      }
>   }
>
>   public HashMap<String, Integer> getCartContents()
>   {
>      return cart;
>   }
>
>   @Remove
>   public void checkout()
>   {
>      System.out.println("To be implemented");
>   }
>}
>
>
>
>Thanks
>
>Erol Akarsu
>
>  
>


--
Burak Emir

http://lamp.epfl.ch/~emir

Reply | Threaded
Open this post in threaded view
|

Re: Java 5.0 annotation in Scala?

Nikolay Mihaylov
In reply to this post by Erol Akarsu-2
Hi there,

Scala already has an annotation framework - what we call attributes,
like in .NET. For now, attributes are only used as hints to the compiler
(like serializable, cloneable, transient, etc), so they don't end up in
the metadata. Furthermore, in its current form they aren't very Java-
like. Scala attributes only have constructor parameters (again, like
in .NET) whereas Java annotations are sets of name-value pairs. On .NET
one can also specify name-value pairs in addition to providing
constructor arguments and obviously we cannot do that either.

The good news is that we are working on extending the syntax of
attribute application to allow for name-value pairs so we can apply a
Java/.NET attribute to a Scala class member and emit the appropriate
information to the class file/.NET assembly. Another problem is that
currently we have no way of expressing the .class notation like in
@Remote(ShoppingCart.class) (or, in C#, typeof(Whatever)). However, we
are commited to solving these problems and exposing to Scala the full
custom metadata capabilities of the host platform.

Stay tuned for further developments.

Nikolay

On Thu, 2006-04-27 at 12:54 +0000, Erol Akarsu wrote:

> Is there any plan to have Java5.0-like annotation framework in Scala?
>
> I believe Scala will be one of the best languages. It will be nice to have this
> annotation feature in Scala. So, we can use Scala to build EJB3 beans.
>
> Here is a small example of EJB3 bean with annotation.
>
>
> @Stateful
> @Remote(ShoppingCart.class)
> public class ShoppingCartBean implements ShoppingCart, Serializable
> {
>    private HashMap<String, Integer> cart = new HashMap<String, Integer>();
>
>    public void buy(String product, int quantity)
>    {
>       if (cart.containsKey(product))
>       {
>          int currq = cart.get(product);
>          currq += quantity;
>          cart.put(product, currq);
>       }
>       else
>       {
>          cart.put(product, quantity);
>       }
>    }
>
>    public HashMap<String, Integer> getCartContents()
>    {
>       return cart;
>    }
>
>    @Remove
>    public void checkout()
>    {
>       System.out.println("To be implemented");
>    }
> }
>
>
>
> Thanks
>
> Erol Akarsu
>

Reply | Threaded
Open this post in threaded view
|

Re: Java 5.0 annotation in Scala?

Martin Odersky
In reply to this post by Burak Emir
Burak Emir wrote:

> Unfortunately, I wanted to document and try that feature thoroughly as a
> reaction to your mail, and then discovered that it's not working right
> now http://scala-webapps.epfl.ch/bugtracking/bugs/displayItem.do?id=579 
> but it should get fixed in a very short time.

I just fixed it. So it should be in the next minor release. -- Martin