DEFAULT keyword in ABAP and Optional Class in Java

简介: DEFAULT keyword in ABAP and Optional Class in Java

It is ok to use this new ABAP syntax about table expression here since object_ext is passed from UI framework and it is rarely possible that there would be partner or customer to manually pass any other value to parameter it_data.

image.png

According to ABAP help, if no row by specified key could be found, exception will be raised, instead of sy-subrc set to a non-zero value for READ TABLE XXX.


image.png

so ABAP provides another key word DEFAULT which allows you to provide a default value if specified row does not exist to avoid exception. In example below, line 17 will raise exception while line 19 not.


image.png

In Java 8 there is similar mechanism: new class Optional is introduced to avoid application developers’ endless of If XXX != null code to check null:

image.png

Unlike many other annotation, this Utility class is not implemented in JVM layer, but just in language layer, as a result it is very easy to develop an Optional class in ABAP as well.


image.png

相关文章
Unable to interpret the implicit parameter configuration with dataType: , dataTypeClass: class java.
Unable to interpret the implicit parameter configuration with dataType: , dataTypeClass: class java.
462 0
|
5月前
|
安全 Java 开发者
Java一分钟之-Optional类:优雅处理null值
【5月更文挑战第13天】Java 8的`Optional`类旨在减少`NullPointerException`,提供优雅的空值处理。本文介绍`Optional`的基本用法、创建、常见操作,以及如何避免错误,如直接调用`get()`、误用`if (optional != null)`检查和过度使用`Optional`。正确使用`Optional`能提高代码可读性和健壮性,建议结合实际场景灵活应用。
165 3
日常报错 - NO constructor found in matching [java.lang.String]解决方法
日常报错 - NO constructor found in matching [java.lang.String]解决方法
414 0
|
12月前
|
XML 数据格式
解决 Cannot convert value of type ‘java.lang.String‘ to required type ‘java.sql.Driver‘ for property ‘
解决 Cannot convert value of type ‘java.lang.String‘ to required type ‘java.sql.Driver‘ for property ‘
236 0
|
Java 关系型数据库 MySQL
15. 成功解决:java: Can't generate mapping method with primitive return type.
今天启动 SpringBoot 项目时,报了如下错误:`java: Can't generate mapping method with primitive return type.`
951 0
|
Java 数据库连接 mybatis
控制台报错 No constructor found in com.base.entity.Menu matching [java.lang.Integer, java.lang.String]
控制台报错 No constructor found in com.base.entity.Menu matching [java.lang.Integer, java.lang.String]
141 0
控制台报错 No constructor found in com.base.entity.Menu matching [java.lang.Integer, java.lang.String]
|
Java
JAVA解决方案:Missing URI template variable ‘customersno‘ for method parameter of type String
解决方案 PathVariable和RequestParam的使用 @PathVariable @RequestParam PathVariable和RequestParam的区别 区别在于一个是用?,一个使用/进行传输数据
321 0
|
XML JSON 数据格式
No converter found for return value of type: class java.util.ArrayList错误问题
No converter found for return value of type: class java.util.ArrayList错误问题
No converter found for return value of type: class java.util.ArrayList错误问题
DEFAULT keyword in ABAP and Optional Class in Java
DEFAULT keyword in ABAP and Optional Class in Java
DEFAULT keyword in ABAP and Optional Class in Java
|
Java 数据库连接 数据格式
解决:Failed to convert value of type 'java.lang.String' to required type 'java.util.Date';的方法
解决:Failed to convert value of type 'java.lang.String' to required type 'java.util.Date'; 发生这一错误的主要原因是Controller类中需要接收的是Date类型,但是在页面端传过来的是String类型,最终导致了这个错误。
48818 0
下一篇
无影云桌面