gpt4 book ai didi

java - 如何解决这个类型删除?

转载 作者:太空宇宙 更新时间:2023-11-04 14:09:53 25 4
gpt4 key购买 nike

我想知道如何解决在 JDK 1.7 中出现的编译失败问题,该代码在 JDK 1.6 中完美运行。

我得到的错误: MatchStrings.java:[71,36] 错误:名称冲突:MatchStrings 中的 with(ElementMatcher) 和 MatchElements 中的 with(ElementMatcher) 具有相同的删除,但两者都不隐藏另一个

我的类(class)存在问题:

public class MatchStrings extends MatchElements
{


public static class StringMatcherImpl extends ElementMatcherImpl<String>
{
public StringMatcherImpl(ElementMatcher<String> matcher)
{
super(matcher);
}
}

public static class PrefixMatcher implements ElementMatcher<String>
{

private final String _prefix;

public PrefixMatcher(String prefix)
{
_prefix = prefix;
}

@Override
public boolean matches(String str)
{
return str.startsWith(_prefix);
}
}

public static class SuffixMatcher implements ElementMatcher<String>
{

private final String _suffix;

public SuffixMatcher(String suffix)
{
_suffix = suffix;
}

@Override
public boolean matches(String str)
{
return str.endsWith(_suffix);
}
}

public static StringMatcherImpl with(ElementMatcher<String> matcher)
{
return new StringMatcherImpl(matcher);
}

public static StringMatcherImpl startingWith(String prefix)
{
return with(new PrefixMatcher(prefix));
}

public static StringMatcherImpl endingWith(String prefix)
{
return with(new SuffixMatcher(prefix));
}

}

public class MatchElements
{

public static class ElementMatcherImpl<E> implements ElementMatcher<E>
{
private ElementMatcher<E> _matcher;

ElementMatcherImpl(ElementMatcher<E> matcher)
{
_matcher = matcher;
}

@Override
public boolean matches(E e)
{
return _matcher.matches(e);
}

public ElementMatcherImpl<E> and(ElementMatcher<E> m)
{
_matcher = new ElementMatcherAndChain<E>(_matcher, m);
return this;
}

public ElementMatcherImpl<E> or(ElementMatcher<E> m)
{
_matcher = new ElementMatcherOrChain<E>(_matcher, m);
return this;
}

@Override
public String toString()
{
return _matcher.toString();
}
}

public static <E> ElementMatcherImpl<E> with(ElementMatcher<E> matcher)
{
return new ElementMatcherImpl<E>(matcher);
}

public static <E> ElementMatcherImpl<E> not(ElementMatcher<E> matcher)
{
return with(new ElementMatcherNegator<E>(matcher));
}

}

最佳答案

public static StringMatcherImpl with(ElementMatcher<String> matcher)

MatchStrings

public static <E> ElementMatcherImpl<E> with(ElementMatcher<E> matcher)

MatchElements键入删除

with(ElementMatcher matcher)

正如 @Tom 所说,从 Java 7 开始,它不再有效。

如果可能,请重命名 with(ElementMatcher<String> matcher)更具体的内容,例如 withStringMatcher(ElementMatcher<String> matcher)

关于java - 如何解决这个类型删除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28457238/

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