java 为什么我得到“类型测试的重复修饰符”以及如何修复它

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36199512/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 01:03:57  来源:igfitidea点击:

Why am i getting " Duplicate modifier for the type Test" and how to fix it

javaanagram

提问by EvilDumplings

I was trying to make a method that returns true if given "Strings" are anagrams. unfortunately i cant even test it and i don know what is wrong. The markers at left says:

如果给定的“字符串”是字谜,我试图制作一个返回 true 的方法。不幸的是,我什至无法测试它,我不知道出了什么问题。左边的标记说:

Multiple markers at this line - Breakpoint:Test - Duplicate modifier for the type Test

此行的多个标记 - Breakpoint:Test - 类型测试的重复修饰符

Here is the source code:

这是源代码:

package zajecia19;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.HashMap;
public 
public class Test {
    public static boolean Anagraamy(String s1, String s2) {
        if (s1.length() != s2.length()) {
            return false;
        }
        HashMap<Character, Integer> map = new HashMap<>();
        for (int i = 0; i < s1.length(); i++) {
            if (map.containsKey(s1.charAt(i))) {
                map.put(s1.charAt(i), map.get(s1.charAt(i)) + 1);
            } else {
                map.put(s1.charAt(i), 1);
            }
            if (map.containsKey(s2.charAt(i))) {
                map.put(s2.charAt(i), map.get(s2.charAt(i)) - 1);
            } else {
                map.put(s2.charAt(i), -1);
            }
        }
        for( Integer value: map.values()){
            if(value != 0 ){
                return false;
            }
        }

        return true;

    }

    public static void main(String[] args) {
        try (BufferedReader br = new BufferedReader(new FileReader("slowa2"))) {
        System.out.println( Anagraamy("abba", "babb"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

回答by GhostCat

Because you have

因为你有

public
public 

there.

那里。

The obvious way to fix that: remove the first one. And next time: pay attention to what the compiler is trying to tell you.

解决这个问题的明显方法:删除第一个。下一次:注意编译器试图告诉你的内容。