mercredi 20 juillet 2016

didSet detection on ANY field?

I've done some searching (and mostly finished C# in depth) but haven't come across what I'm looking for.

I'm curious though if there is a way (hacky is ok!) that I can get a generic notification or hook from ANY set operation on a class.

The reason is I am working on a framework that saves the state of the app as a class. And when the state changes, I want a notification from it.

Setting up a didSet (i.e. firing an alert in every setter call) on every possible field is tedious overkill. Do you know of any way I can get hook for any time a field is changed on a class?





Term for Reflective Web

Years ago, possibly in the late 90s, someone proposed having websites contain information that described what they did. This may have been a precursor to meta-tags. I believe it was an effort to help machines categorize websites and offer suggestions when doing a search. So the tags would have been used to describe the site content instead of meta information regarding the page itself.

I'm looking for the term that was used. It was something like "The Intrinsic Web" or "The Reflective Web". Whatever it was, it effectively fizzled out once Google came along with their fancy search algorithm.

Thanks, Mike





Android: Is there a way to read com.android.internal.R.xml.power_profile from my app code?

I need to know the values of power_profile.xml. So is this accessible from app? The class PowerProfile is accessible by java reflection and this class uses power_profile.xml.

The following link shows the class PowerProfile: http://ift.tt/2a8CBsg

Can I write a java class that reads the xml values ​​of my phone?





how to extract A from typeA (val typeA = typeOf[A])?

there is a case class and a Type variable:

case class A()
val typeA = typeOf[A]
fun(typeA)

and there is a function:

def fun(t: Type){  
    // how to use 't' to create List[A]
    val l = List[/*convert 't' to A type*/]()
}

how to do?





How to convert Type to TypeTag in scala?

there is a case class:

case class A()

And there is a Type variable:

val typeA = typeOf[A]

I want to create object val l = List[A](), but I only have typeA now and create object by val l = List[/*convert typeA*/](), how to do?





Eclipse PDE: Reflections Library not finding packages

The org.reflections library does not function correctly when it's used inside an Eclipse Plugin project.

For instance, the following code should return all classes of a given subtype in a given package:

Reflections reflections = new Reflections("my.package");
Set<Class<? extends Subtype>> classes = reflections.getSubTypesOf(Subtype.class);

When running the project as a Plugin, classes will be empty. Inserting a main() and running it as a normal Java application will correctly return the expected classes.

I've tried to:

Include the Reflections library as a normal third-party jar dependency

Include the Reflections library as an OSGi bundle (http://ift.tt/2afGKNd)





mardi 19 juillet 2016

What's the easiest way to convert a Scala reflection MethodSymbol/MethodSignature to a Java Method?

Scala reflection is designed for both compilation time and run time. So it can identify polymorphic method more effectively than Java (see my previous post In Scala Reflection, How to get generic type parameter of a concrete subclass?), which suffers from type erasure.

However, this method can only be invoked using Scala reflection's mirror, which is slightly slower than its java counterpart, I would like to know if there is an easy way to convert Scala MethodSymbol, which is returned directly by Type.members, or MethodSignature, which is returned by Type.member.SignatureIn(Type) to a Java method that can be directly invoked through Java reflection API.

Is it possible?