On Sat, Jun 25, 2016 at 11:52 AM, Jan Vrany <[email protected]> wrote:
> > In Java you *cannot* annotate any language element. You can annotate > class, methods, instance variables, method arguments and temporaries and > packages. > > > Then when I take an annotation, for example an hibernate annotation: > > @Entity@Table(name = "EMPLOYEE") > > In the case of Hibernate, these annotation are for a class and they are > used at *runtime* to bind the class instances with database entries > (elements of this class are stored in the table EMPLOYEE). > > Now I've never seen anyone doing that, but as you can access the > annotation at runtime, and you can extract from the annotation its name and > its parameters (for example you could extract "Table" and "name -> > EMPLOYEE". Then, using the Java reflective features, you can do something > like: > > method = obj.getClass().getMethod(methodName, param1.class, param2.class, ..); > > method.invoke(obj, arg1, arg2,...); > > And this way you execute a method named "Table", "name" or "EMPLOYEE" with > the parameter you want, as you could execute a method from any string > matching a method name. We have the same primitive in Pharo on > CompiledMethod. > > > I would not say that pragmas are more powerful in Java. Can you give an > example of something you can do with the Java annotation that you can't do > with Pharo pragmas ? > > > Out of a curiosity, how can I annotate class, instance variable, method > argument or temporary, or package. > How can I annotate the pragma definition itself? How can I retrieve > annotations of a pragma definition? > > I mean, I understand that you can *achieve* same effect, but you *can* > achieve it as well with no pragma support at all. > Agreed. We can do the same thing, but we do it differently. > Jan > > In Slang we use pragma to annotate argument and temporary variables and it > works just fine. When you describe in Pharo classes and instance variables > using Magritte you can do the same thing as just annotating them. > > > > Stef >> >> >
