ABAP和Java的tag(marker) interface
In my previous blog How many fat interfaces are there in SAP system I introduce the concept of “fat interface”. In this blog let’s explore the concept of tag interface. There is definition for tag interface in ABAP help:
“Specific predefined global interface. By integrating the tag interface, classes or other interfaces stand out against the ABAP runtime environment. A tag interface generally does not contain its own interface components, but instead assigns a particular task to the integrating classes or interfaces and changes the way they are handled by the ABAP Compiler.“ And in fact this is not a specific concept of ABAP, but exists in many other language as well.
ABAP tag interface
One of the most famous tag interface in ABAP is if_serializable_object.
I used it in my blog Singleton bypass – ABAP and Java.
An object instance of class which implements this tag interface could be serialized to an XML String.
The actual serialization and deserialization is done in the kernel.
Another tag interface IF_BADI_INTERFACE
In you BAdI definition, it is impossible to use an interface without including this tag interface.
Even if you bypass this check via tricks like debugging in ABAP layer, there is still kernel check in the runtime as last defense.
Tag interface in Java
As I mentioned the tag interface is a generic concept which is available in many other language like Java. See more generic definition in Wikipedia.
The tag/ marker interface pattern is a design pattern in computer science, used with languages that provide run-time type information about objects. It provides a means to associate metadata with a class where the language does not have explicit support for such metadata.
Java Serialization
Still use serialization for example. Java has its own tag interface for serialization, Serializable. ( just exactly the same logic as if_serializable_object in ABAP ).
When the serialization is performed, JDK will check whether the instance has implemented this interface by instanceof.
In ABAP we have similar keyword to achieve the same.
Cloneable tag interface
Consider the following source code:
public class Employee implements Cloneable {
private String name;
private List<String> skill = new ArrayList<String>();
public Employee(String name){
this.name = name;
}
public Employee addSkill(String name){
this.skill.add(name);
return this;
}
public static void main(String[] arg){
Employee jerry = new Employee("Jerry");
jerry.addSkill("ABAP");
jerry.addSkill("Java");
jerry.addSkill("JavaScript");
Employee ji = null;
try {
ji = (Employee) jerry.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
System.out.println("Clone done");
}}
When executed, it will raise the following exception:
Simply add the tag interface Cloneable:
And the error disappears:
This test proves that there must be some check in the native implementation of clone method in JDK.
Further reading
I have written a series of blogs which compare the language feature among ABAP, JavaScript and Java. You can find a list of them below:
- Lazy Loading, Singleton and Bridge design pattern in JavaScript and in ABAP
- Functional programming – Simulate Curry in ABAP
- Functional Programming – Try Reduce in JavaScript and in ABAP
- Simulate Mockito in ABAP
- A simulation of Java Spring dependency injection annotation @Inject in ABAP
- Singleton bypass – ABAP and Java
- Weak reference in ABAP and Java
- Fibonacci Sequence in ES5, ES6 and ABAP
- Java byte code and ABAP Load
- How to write a correct program rejected by compiler: Exception handling in Java and in ABAP
- An small example to learn Garbage collection in Java and in ABAP
- String Template in ABAP, ES6, Angular and React
- Try to access static private attribute via ABAP RTTI and Java Reflection
- Local class in ABAP, Java and JavaScript
- Integer in ABAP, Java and JavaScript
- Covariance in Java and simulation in ABAP
- Various Proxy Design Pattern implementation variants in Java and ABAP
- Tag(Marker) Interface in ABAP and Java
- Bitwise operation ( OR, AND, XOR ) on ABAP Integer
- ABAP ICF handler and Java Servlet
要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24475491/viewspace-2713954/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 什麼是Java Marker Interface(標記介面)Java
- ABAP的Package interface, 安卓的manifest.xml和Kubernetes的CapabilitiesPackage安卓XML
- 給你的ABAP物件打上標籤(Tag)物件
- ABAP和Java的destination和JNDIJava
- SAP ABAP Netweaver裡的胖介面(fat interface)
- JAVA 中interface 和 abstract 區別Java
- java中的interface(介面)Java
- ABAP和Java單例模式的攻防Java單例模式
- ABAP和Java SpringBoot的單元測試JavaSpring Boot
- Java和ABAP裡的外部類和內部類Java
- Java-介面(interface)Java
- SAP ABAP和Java的動態代理實現Java
- SAP ABAP ADBC和Java JDBC的使用比較JavaJDBC
- ABAP SICF服務和Java Servlet的比較JavaServlet
- ABAP和Java的單元測試Unit TestJava
- Java的位元組碼和ABAP load的比較Java
- SAP Hybris Commerce的JSP tag和SAP BSP tag的比較JS
- trait in rust, and comparison with interface in javaAIRustJava
- Typescript的interface、class和abstract classTypeScript
- 你真的會用ABAP, Java和JavaScript裡的constructor麼?JavaScriptStruct
- 淺談Java和SAP ABAP的靜態代理和動態代理,以及ABAP面向切面程式設計的嘗試Java程式設計
- public interface View介面和public interface ViewResolver介面介紹View
- ts中的type 和 interface 區別
- TypeScript 裡 interface 和 type 的區別TypeScript
- Java的Covariance設計原理和SAP ABAP的模擬實現Java
- null in ABAP and nullpointer in JavaNullJava
- Java基礎二十三(interface)Java
- 【詳解】JNI (Java Native Interface) (二)Java
- 【詳解】JNI (Java Native Interface) (三)Java
- 【詳解】JNI (Java Native Interface) (四)Java
- 【詳解】JNI(Java Native Interface)(一)Java
- 【GiraKoo】Java Native Interface(JNI)的空間(引用)管理Java
- Standard ABAP Debugger 和 Classic ABAP Debugger 的實現差異
- ABAP Netweaver 和 ABAP Platform 這兩個名詞的辨析Platform
- PHP中的 抽象類(abstract class)和 介面(interface)PHP抽象
- Golang中的interface程式碼和允許效果Golang
- 【區分】Typescript 中 interface 和 typeTypeScript
- JavaScript和ABAP的尾遞迴JavaScript遞迴