marker-interfaces

I want to load a specific class based on a flag instead of loading two class and using one the required in Springs

三世轮回 提交于 2019-12-24 10:40:03
问题 In configurations I have a flag isFlagEnabled. So I have to read the flag from spring config and based on that I want to execute specific class A or B . Meaning I want to load A class only when isFlagEnabled is true and similarly load class B only when isFlagEnabled is false. I have written the below code but i am stuck when ingesting . public interface MediatorInt { public void init(); } class A implements MediatorInt { init() { It does some task } } class B implements MediatorInt { init(){

Marker Interfaces in Java?

假如想象 提交于 2019-12-17 02:26:33
问题 I was being taught that Marker interface in Java is an empty interface and is used to signal to compiler or JVM that the objects of the class implementing this interface must be treated in a special way, like serializing, cloning, etc. But lately I have learned that it actually has nothing to do with the compiler or the JVM. For example, in case of Serializable interface the method writeObject(Object) of ObjectOutputStream does something like instanceOf Serializable to detect whether the

Marker Interfaces

 ̄綄美尐妖づ 提交于 2019-12-09 03:34:19
问题 Could somebody pls explain the contract of marker interfaces in java? For Ex: If Clonable is a Marker Interface with no fields/methods, then where is the clone() defined? Why should we implement Clonable i/f whenever clone() is used? Well my question was, if clone() is a method of java.lang.Object class, why implement Clonable i/f to override clone() . Could somebody elaborate on this convention of java ? Thanks in Advance 回答1: clone() is defined in the java.lang.Object class which all

can marker interface like serializable contain default methods?

╄→尐↘猪︶ㄣ 提交于 2019-12-04 18:29:46
问题 I think it can't, because marker interface principle is to not have any methods, but since default methods are not abstract I am not sure. 回答1: A "Marker" interface is just a regular interface as far as Java is concerned. Thus, it can have default methods just as any (Java-8) interface can. Now, as to whether this violates the principle of a Marker interface, I would have to say yes. A Marker interface should act as a flag of sorts, only identifying that a class meets some external criteria.

can marker interface like serializable contain default methods?

帅比萌擦擦* 提交于 2019-12-03 12:44:11
I think it can't, because marker interface principle is to not have any methods, but since default methods are not abstract I am not sure. A "Marker" interface is just a regular interface as far as Java is concerned. Thus, it can have default methods just as any (Java-8) interface can. Now, as to whether this violates the principle of a Marker interface, I would have to say yes. A Marker interface should act as a flag of sorts, only identifying that a class meets some external criteria. Now, it can be a Marker interface and have abstract/default methods, but it will no longer purely meet the

Marker Interfaces

喜夏-厌秋 提交于 2019-12-01 18:11:41
Could somebody pls explain the contract of marker interfaces in java? For Ex: If Clonable is a Marker Interface with no fields/methods, then where is the clone() defined? Why should we implement Clonable i/f whenever clone() is used? Well my question was, if clone() is a method of java.lang.Object class, why implement Clonable i/f to override clone() . Could somebody elaborate on this convention of java ? Thanks in Advance EdC clone() is defined in the java.lang.Object class which all classes extend from, however it is protected . This is actually a concrete method implementation that does a

Why java annotations?

做~自己de王妃 提交于 2019-11-30 14:42:59
问题 i want to ask why are the java annotations used so much... I know that they replaced xml configuration in for example jpa, but why is this kind configuration used at all? Consider this piece of code: @Entity class Ent{ // some fields } //... somewhere in the other file far far away class NonEnt{ // whatever here } Now, when I try to put this in persistence context, with EntityManager 's persist method, I get runtime error(better would be to get compile error) with trying to persist NonEnt

Why does ObjectOutputStream.writeObject not take a Serializable?

試著忘記壹切 提交于 2019-11-30 12:47:03
问题 Why does ObjectOutputStream.writeObject(Object o) not take a Serializable? Why is it taking an Object ? 回答1: This is because writeObject in ObjectOutputStream overrides the method in the ObjectOutput interface which does not require that the object be Serializable . The ObjectOutput interface specifies methods that allow objects to be written to a stream or underlying storage, but this may be achieved by a process other than serialization. The ObjectOutputStream implements this functionality,