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
- WPF备忘录(7)WPF图片资源路径介绍
- 植入式攻击入侵检测解决方案
- 神经网络太臃肿?教你如何将神经网络减小四分之一
- WPF中ListView如何改变选中条背景颜色
- WPF Trigger for IsSelected in a DataTemplate for ListBox items
- C#基础知识回顾--BackgroundWorker介绍
- Elasticsearch 瞬间入门
- 使用OpenLDAP 操作 Windows Active Directory
- 优化算法:到底是数学还是代码?
- Email 服务器之 SPF 记录
- WPF中播放声音媒体文件
- 设计模式学习--装饰者模式(Decorator Pattern)
- SQL Server 存储过程
- MySQL 转换 latin1 到 UTF-8
- java教程
- Java快速入门
- Java 开发环境配置
- Java基本语法
- Java 对象和类
- Java 基本数据类型
- Java 变量类型
- Java 修饰符
- Java 运算符
- Java 循环结构
- Java 分支结构
- Java Number类
- Java Character类
- Java String类
- Java StringBuffer和StringBuilder类
- Java 数组
- Java 日期时间
- Java 正则表达式
- Java 方法
- Java 流(Stream)、文件(File)和IO
- Java 异常处理
- Java 继承
- Java 重写(Override)与重载(Overload)
- Java 多态
- Java 抽象类
- Java 封装
- Java 接口
- Java 包(package)
- Java 数据结构
- Java 集合框架
- Java 泛型
- Java 序列化
- Java 网络编程
- Java 发送邮件
- Java 多线程编程
- Java Applet基础
- Java 文档注释
- Android圆角头像工具类详解
- Android实现系统消息推送
- Android仿微信QQ聊天顶起输入法不顶起标题栏的问题
- Android实现倒计时的按钮效果
- 腾讯位置服务实现轨迹回放
- 有一种遗憾,是跑程序却没用上_______
- Android使用注解代替枚举节省系统内存开销的方法
- Android实现自定义验证码输入框效果(实例代码)
- flutter 实现多布局列表的示例代码
- flutter TextField换行自适应的实现
- 如何造个android Flow流式响应的轮子
- Flutter混合开发详解
- Android 单双击实现的方法步骤
- Android多渠道打包时获取当前渠道的方法
- Flutter Dio二次封装的实现