How to check a variable against Union type during runtime?

In Python 3.8 and later, the approach suggested by MSeifert and Richard Xia can be improved by not using the undocumented attributes __origin__ and __args__. This functionality is provided by the new functions typing.get_args(tp) and typing.get_origin(tp): >> from typing import Union, get_origin, get_args >> x = Union[int, str] >> get_origin(x), get_args(x) (typing.Union, (<class ‘int’>, <class … Read more

Can java annotation have complex return type like HashMap

No, annotation elements can only be primitive types, Strings, enum types, Class, other annotations, or arrays of any of these. The typical way to represent these kinds of structures would be to declare another annotation type public @interface TableMapping { public String dbName(); public String tableName(); } then say @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) public @interface column { … Read more

Can I use expressions in Apache Shiro security annotations?

Look at the classes in http://shiro.apache.org/static/current/apidocs/org/apache/shiro/authz/aop/package-summary.html, especially PermissionAnnotationHandler. There you can see that all Shiro does when encountering the @RequiresPermissions annotation is call getSubject().isPermitted(permission) and does no substitution inside the annotation value at all. You would have to somehow override that handler if you wanted this kind of functionality. So to answer your question: yes, … Read more

Deriving from a class that has Annotation @PostConstruct

After testing this scenario, the @PostConstruct method in the base class WILL automatically be called. The flow goes like this: When the child class is created, you are in the constructor of the child class, you then are forced into the parent class automatically. Once the parent class constructor is done you are sent back … Read more

Is there a way to pass a Java annotation as a parameter?

Yes, you can pass around annotations like this (just as if they were normal interfaces). The only thing you can’t do is to create instances of that interface at runtime. You can only take existing annotations and pass them around. import java.lang.annotation.*; public class Example { @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public static @interface Number { int value(); … Read more

What does the @code java annotation do

{@code …} is a Javadoc tag that tells Javadoc that the text inside the braces is source code and should not be treated as HTML. Javadoc should also format the text in a code block differently than the other text. This is a similar concept to the “code sample” text that the editor for StackOverflow … Read more

How to use Hibernate @Any-related annotations?

Hope this article brings some light to the subject: Sometimes we need to map an association property to different types of entities that don’t have a common ancestor entity – so a plain polymorphic association doesn’t do the work. For example let’s assume three different applications which manage a media library – the first application … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)