I thought this should be obvious but I can't find it.
Now that fields can have annotations, I thought this should be reflected in the JavaBean spec, but I can't find it.
What I mean:
JavaBean is a specification that allows you to treat objects in an uniform way by discovering their properties, and then reading and writing them.
As PO...
I defined my own custom annotation
@Target(value={ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface MyCustomAnnotation {
Class<?> myType();
}
how, if at all, can I make the attribute optional
...
Do you think you are a java wizard?
That you are well versed in the secrets of the reflection API?
public @interface @a {}
public @interface @b {}
@Mark public @interface @c {}
@Mark public @interface @d {}
public @interface @e {}
public Class C
{
@a @b @c @d @e public void x();
}
public class Solver
{
public Annotation[]...
Hi,
Is metaprogramming possible in javascript??
During my routine work, i happened to write the chained javascript function which is something like LINQ expression to query the JSON result.
var Result = from(obj1).as("x").where("x.id=5").groupby("x.status").having(count("x.status") > 5).select("x.status");
It works perfectly and giv...
According to the class ElementType in the API, you can annotate local variables and method parameters.
How is that done?
...
In emacs I have various functions to manipulate text. Now that I'm using xcode, I suppose I could make emacs my default editor, but I want to browse obj-c objects and such, so I'd rather just implement my most used text manipulation commands for xcode.
First on my list, I'd like a command that moves the text of the current line up/down...
How can I make this code work?
class Meta
@array = [:a,:b]
def self.method_missing(name, *args, &block)
if @array.include? name
self.class.send(:define_method, name) do
do_call(name)
end
else
puts "[#{name.inspect}] ...
In C++, Is it possible to enumerate over an enum (either runtime or compile time (preferred)) and call functions/generate code for each iteration?
Sample use case:
enum abc
{
start
a,
b,
c,
end
}
for each (__enum__member__ in abc)
{
function_call(__enum__member__);
}
Plausible duplicates:
C...
How can I do what they are talking about here, but in Ruby?
How would you do the function on an object? and how would you do a global function (see jetxee's answer on the post mentioned)?
EXAMPLE CODE:
event_name = "load"
def load()
puts "load() function was executed."
end
def row_changed()
puts "row_changed() function was execu...
Core problem:
I want to be able to take an instance of a templated class, say:
template<class a, class b, class c> class foo;
foo<int, float, double>;
and then do something like:
foo<int, float, double>::value; //Evaluates to a unique number
foo<long, float, double>::value; //Evaluates to a different unique number
foo<int, float, d...
I have a metafunction:
struct METAFUNCION
{
template<class T>
struct apply
{
typedef T type;
};
};
Then I define a helper:
template<class T1, class T2>
struct HELPER
{
};
And then I have second metafunction which derives from the METAFUNCTION above and defines partial specialization of apply struct:
struct METAFUNCION2...
Groovys' NodeBuilder uses
def someBuilder = new NodeBuilder()
someBuilder.people(kind:'folks', groovy:true) {
person(x:123, name:'James', cheese:'edam') {
project(name:'groovy')
project(name:'geronimo')
}
person(x:234, name:'bob', cheese:'cheddar') {
project(name:'groovy')
project(name:'drools')
}
}
whereas ...
We have a need to generate Java source code. We do this by modeling the abstract syntax tree and have a tree walker that generate the actual source code text. This far all good.
Since my AST code is a bit old, it does not have support for annotations and generics. So I'm looking around for open projects to use for future projects with c...
Taken from a previous post with some modifications to respond to sepp2k's comment about namespaces, I have implemented String#to_class method. I'm sharing the code here and I do believe that it could be refactored someway specially the "i" counter. Your comments are appreciated.
class String
def to_class
chain = self.split "::"...
I've encountered a Groovy meta-programming problem which I'm unable to solve.
When adding the static method foo() to the class FooBar, then FooBar.foo() works as expected:
FooBar.metaClass.static.foo = {
println "hello"
}
FooBar.foo()
However, I instead add the same static method foo() to the class Object, then FooBar.foo() fails...
Java has annotations and that is good. However, some developers feel that it is best to annotate code with metadata using xml files - others prefer annotations but would use metadata to override annotations in source code.
I am writing a Java framework that uses annotations. The question is: is there a standard way to define and parse m...
Let's say I have an XML::Element...I want to do something like:
my_xml_element.send("parent.next_sibling.next_sibling")
...
This is just something that has bothered me for the last couple of days, I don't think it's possible to solve but I've seen template magic before.
Here goes:
To get the number of elements in a standard C++ array I could use either a macro (1), or a typesafe inline function (2):
(1)
#define sizeof_array(ARRAY) (sizeof(ARRAY)/sizeof(AR...
Is it possible to make a custom operator so you can do things like this?
if ("Hello, world!" contains "Hello") ...
Note: this is a separate question from "Is it a good idea to..." ;)
...
Hi,
Disclaimer: the question is completely different from Inheritance instead of typedef and I could not find any similar question so far
I like to play with c++ template meta-programming (at home mostly, I sometimes introduce it lightly at work but I don't want to the program to become only readable to anyone who did not bother learni...