reflection

Get MethodHandle from lambda object

徘徊边缘 提交于 2020-01-14 04:03:27
问题 From java.lang.invoke.LambdaMetafactory: The recommended mechanism for evaluating lambda expressions is to desugar the lambda body to a method, invoke an invokedynamic call site whose static argument list describes the sole method of the functional interface and the desugared implementation method, and returns an object (the lambda object) that implements the target type. And from inspection this is at least what Oracle JDK does. My question: given a lambda object is there a way to find the

Hive : reflect function

荒凉一梦 提交于 2020-01-14 04:00:37
问题 Im trying to use Reflect function of Hive which have this signature : reflect(class, method[, arg1[, arg2..]]) I want to ckeck if a column c with value hello world ! contains world , so I wrote : with a as (select "hello world !" as c) select reflect("java.lang.String",c ,"contains", "world") from a But it didnt work because it does not respect the signature, so i tried this with a as (select "hello world !" as c) select reflect(reflect("java.lang.Object","toString",c) ,"contains", "world")

C# reflection and finding all references of a Class/Property in my project solution

亡梦爱人 提交于 2020-01-14 03:49:06
问题 I have a class named Test and I instantiated that class in several other classes. Is there any way I could find all references to the Class "Fix" programmatically. I know I could find that with Find All References in VisualStudio but I want to achieve this programmatically for my requirement. Any help, please. Example: Fix.cs namespace Testing { public class Fix { public string fixName = "Name"; } } CodeFix.cs namespace Testing { public class CodeFix { private string GetName() { Fix fix = new

C# Reflection: How to Emit a class

核能气质少年 提交于 2020-01-14 03:37:14
问题 I have a class, ReferenceObject, that I want Emitted into the dll I create. How do I do this without writing every method with Emit? I basically want this class added to the dll I generate. Here is the class: public class ReferenceObject { private readonly int value; public ReferenceObject(int pValue) { value = pValue; } public override string ToString() { return value.ToString(); } public int Value() { return value; } public int ID() { return value; } #region == Operator public static bool

Trouble with “Assembly.EntryPoint.Invoke” [C#]

不打扰是莪最后的温柔 提交于 2020-01-13 19:30:30
问题 I have the following problem: I am compiling C#-code at runtime using the CSharpCodeProvider in Microsoft.CSharp . The created application runs perfectly, if I double-click on the generated file. If, however, I am loading my created assembly with Assembly.Load and invoking the entrypoint-method with Assembly.Load("...").EntryPoint.Invoke(null, null) , I get a NullReferenceException . The NullReferenceException is referring to the value of the .EntryPoint -Property. When I debug the variable

Can I tell which template instance class(es) my class is inheriting from?

倖福魔咒の 提交于 2020-01-13 13:52:09
问题 Given this code: template < int I > class Foo { public: int v; Foo() { v = I; } virtual ~Foo() {} }; class Bar : public Foo<0>, public Foo<3> { public: template < int I > int getValue() { return Foo<I>::v; } }; int main() { Bar b; cout << b.getValue<0>() << endl; // prints 0 cout << b.getValue<3>() << endl; // prints 3 cout << b.getValue<4>() << endl; // compiler error return 0; } Is it possible to iterate over all Foo<i> classes from which Bar inherits? We can assume that i is between 0 and

Can I tell which template instance class(es) my class is inheriting from?

℡╲_俬逩灬. 提交于 2020-01-13 13:51:12
问题 Given this code: template < int I > class Foo { public: int v; Foo() { v = I; } virtual ~Foo() {} }; class Bar : public Foo<0>, public Foo<3> { public: template < int I > int getValue() { return Foo<I>::v; } }; int main() { Bar b; cout << b.getValue<0>() << endl; // prints 0 cout << b.getValue<3>() << endl; // prints 3 cout << b.getValue<4>() << endl; // compiler error return 0; } Is it possible to iterate over all Foo<i> classes from which Bar inherits? We can assume that i is between 0 and

Macro to access source code of function at runtime

核能气质少年 提交于 2020-01-13 11:35:29
问题 Using Scala macros I would like to get access to source code of function f. Here is simplified example of my problem: def logFImplementation(f: => Boolean) { val sourceCodeOfF: String = ... // <-- how to get source code of f?? println("Scala source of f=" + sourceCodeOfF) } so for: logFImplementation { val i = 5; List(1, 2, 3); true } it should print: Scala source of f=val i: Int = 5; immutable.this.List.apply[Int](1, 2, 3); true (Right now I tested Macro to access source code text at runtime

Java reflection: Find fields of a subclass

一笑奈何 提交于 2020-01-13 10:35:10
问题 I have a class hierarchy like so: (=> means "is a subclass of") anonymous instance class => abstract class => generic abstract class or more succinctly: C => B => A When executing, "C" calls one of "A"'s methods. Within that method in "A", I want to use reflection to find protected fields of the object that are defined in class "B". (So these are fields that "C" and "B" can see, but not "A".) How would I do this with Java reflection? And how can I future-proof it in case I add something

Java reflection: Find fields of a subclass

南笙酒味 提交于 2020-01-13 10:34:02
问题 I have a class hierarchy like so: (=> means "is a subclass of") anonymous instance class => abstract class => generic abstract class or more succinctly: C => B => A When executing, "C" calls one of "A"'s methods. Within that method in "A", I want to use reflection to find protected fields of the object that are defined in class "B". (So these are fields that "C" and "B" can see, but not "A".) How would I do this with Java reflection? And how can I future-proof it in case I add something