annotations

OSGi/Felix Declarative Services: How to filter the services to be bound?

依然范特西╮ 提交于 2020-01-03 15:32:17
问题 I am using Apache Felix and its Declarative Services (SCR) to wire the service dependencies between bundles. For example, if I need access to a java.util.Dictionary I can say the following to have SCR provide one: /** * @scr.reference name=properties interface=java.util.Dictionary */ protected void bindProperties(Dictionary d) { } protected void unbindProperties(Dictionary d) { } Now, I have more than one Dictionary service available, and I want to filter them using the "name" service

Get [key] property from ViewModel

只愿长相守 提交于 2020-01-03 13:40:04
问题 I have a ViewModel which has a [key] property and i would like to get that from an instance of that view model. My code looks something like this (fictional models) class AddressViewModel { [Key] [ScaffoldColumn(false)] public int UserID { get; set; } // Foreignkey to UserViewModel } // ... somewhere else i do: var addressModel = new AddressViewModel(); addressModel.HowToGetTheKey..?? So i need to get the UserID (in this case) from the ViewModel. How can i do this? 回答1: If you are stuck or

Get [key] property from ViewModel

南笙酒味 提交于 2020-01-03 13:38:08
问题 I have a ViewModel which has a [key] property and i would like to get that from an instance of that view model. My code looks something like this (fictional models) class AddressViewModel { [Key] [ScaffoldColumn(false)] public int UserID { get; set; } // Foreignkey to UserViewModel } // ... somewhere else i do: var addressModel = new AddressViewModel(); addressModel.HowToGetTheKey..?? So i need to get the UserID (in this case) from the ViewModel. How can i do this? 回答1: If you are stuck or

How to create custom annotations like BeanProperty

∥☆過路亽.° 提交于 2020-01-03 08:52:53
问题 In Scala it's possible to use the annotation @BeanProperty to automatically generate getters and setters to a field. How can I create my own annotation that behaves like that? I'm interested in creating annotations that changes the source code, like @BeanProperty does. As an example, how could I create an annotation that only generated get methods? Thanks. 回答1: Two words: compiler plugin. It is not easy, and the documentation is sparse, but that is one way to do it. Future versions of Scala

How to create custom annotations like BeanProperty

风流意气都作罢 提交于 2020-01-03 08:52:37
问题 In Scala it's possible to use the annotation @BeanProperty to automatically generate getters and setters to a field. How can I create my own annotation that behaves like that? I'm interested in creating annotations that changes the source code, like @BeanProperty does. As an example, how could I create an annotation that only generated get methods? Thanks. 回答1: Two words: compiler plugin. It is not easy, and the documentation is sparse, but that is one way to do it. Future versions of Scala

When/why would I want to use Groovy's @CompileStatic?

这一生的挚爱 提交于 2020-01-03 07:29:07
问题 I've read this: http://docs.groovy-lang.org/latest/html/gapi/groovy/transform/CompileStatic.html, and this: Should I use Groovy's @CompileStatic if I'm also using Java 7, and understand there are certainly performance improvements to be had but is that it? I don't understand exactly what @CompileStatic does. Are there certain classes on which adding @CompileStatic is a no-brainer? Where would I not want it? 回答1: To cite my part of my answer to Should I use Groovy's @CompileStatic if I'm also

Detect when a second annotation is selected in a MKMapView

不打扰是莪最后的温柔 提交于 2020-01-03 07:25:10
问题 When a use selects an annotation in a map, I show a bottom view with informations, such as the google maps app. I'm showing it in the map's delegate : - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view When the user deselects it (by taping anywhere on the map), I hide my bottom view. This is done in the opposite delegate method : - (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view It works well, I'm happy with it. However,

Run a method before and after a called method in Java

放肆的年华 提交于 2020-01-03 07:23:32
问题 I'm trying to write a Java program such that after calling a methodA() , first a method named methodBeforeA() is called and then methodA() gets executed followed by another method being called named, methodAfterA() . This is very similar to what Junit does using Annotations (using the @Before, @Test, @After), so i think it should be possible using reflection but i don't have a very good clue. 回答1: AspectJ allows you to specify cutpoints before method entry and after method exit. http://www

Can annotation processor be used for code generation?

限于喜欢 提交于 2020-01-03 07:21:09
问题 Let's say I define an annotation called @MyAnnotation . There is a class X which is declared as: @MyAnnotation class X { .... } Now at compile time I want to inspect all classes annotated with @MyAnnotation and do some code generation to more java source files that need to be compiled as well in the same process. Is this possible using java annotation processor or some other tool? 回答1: You may take a look at the Java apt (Annotation Processing Tool) for such a thing. You can find the Getting

Django: Annotation not working?

你离开我真会死。 提交于 2020-01-03 05:14:11
问题 I have two models, Product, which has a one-to-many relationship with a RatingEntry: >>> product_entries = models.Products.objects.all() >>> annotated = product_entries.annotate(Count("ratingentry")) >>> len(annotated) 210 >>> a = annotated.filter(ratingentry__count__lte = 10) >>> b = annotated.filter(ratingentry__count__gt = 10) >>> len(a) 10 >>> len(b) 200 >>> len(a | b) 10 //should be 210 If I change a and b to lists, and concatenate them, the length works out to 210. Any idea what's going