gpt4 book ai didi

java - 隐藏枚举常量

转载 作者:行者123 更新时间:2023-12-01 18:59:40 24 4
gpt4 key购买 nike

我将枚举作为按预序遍历树结构的指南(迭代器使用这些枚举常量来决定如何遍历树):

/**
* The result type of an {@link IVisitor} implementation.
*
* @author Johannes Lichtenberger, University of Konstanz
*/
public enum EVisitResult {
/** Continue without visiting the siblings of this node. */
SKIPSIBLINGS,

/** Continue without visiting the descendants of this node. */
SKIPSUBTREE,

/** Continue traversal. */
CONTINUE,

/** Terminate traversal. */
TERMINATE,

/** Pop from the right sibling stack. */
SKIPSUBTREEPOPSTACK
}

但是,最后一个枚举常量仅用于内部访问者,并且不应由使用公共(public) API 的用户使用。有什么想法可以隐藏“SKIPSUBTREEPOPSTACK”吗?

最佳答案

您所能做的就是记录不应使用它。

另一种方法是使用接口(interface)

public interface EVisitResult {
}

public enum PublicEVisitResult implements EVisitResult {
/** Continue without visiting the siblings of this node. */
SKIPSIBLINGS,

/** Continue without visiting the descendants of this node. */
SKIPSUBTREE,

/** Continue traversal. */
CONTINUE,

/** Terminate traversal. */
TERMINATE,
}

enum LocalEVisitResult implements EVisitResult {
/** Pop from the right sibling stack. */
SKIPSUBTREEPOPSTACK
}

关于java - 隐藏枚举常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12677790/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com