在 Java 中键入同义词 [英] Type synonyms in java

查看:35
本文介绍了在 Java 中键入同义词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论如何(一种解决方法)在 Java 中定义类型同义词,类似于 Scala 中的以下定义?

Is there anyway (a workaround) to define type synonyms in Java, similar to the following definition in Scala?

type Row = List[Int];

<小时>

虽然可能不完全一样,但我想到了以下代码(我用ArrayList替换了List,因为List是Java中的一个接口):


Though it might not be exactly the same, I was thinking of the following code (I replaced List with ArrayList, since List is an interface in Java):

public class Row extends ArrayList<Integer>{}

在java中有没有其他方法可以实现类型同义词机制?

Is there any other way to achieve type synonym mechanism in java?

推荐答案

很遗憾没有.请参阅 是否有 Java 等效项或 C++ 中 typedef 关键字的方法? 对于这个问题的旧副本,使用 C++ 术语而不是 Scala 术语.

Unfortunately not. See Is there a Java equivalent or methodology for the typedef keyword in C++? for an older duplicate of this question, using C++ terminology instead of Scala terminology.

这篇关于在 Java 中键入同义词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆