简体   繁体   English

Java错误: <identifier> 预期在受保护的接口内部

[英]Java Error: <identifier> expected inside protected interface

I am facing the following problem. 我正面临以下问题。 I was trying to put together a simple tutorial on the strategy in Java when I ran into a problem. 当我遇到问题时,我正试图整理有关Java策略的简单教程。 The compiler gives me an "<identifier> expected" error on the void do(int i); 编译器在void do(int i);上给了我一个“ <identifier>预期”错误void do(int i); in the interface: Here is the full class: 在界面中:这是完整的类:

import java.util.*;
public class Data {
private List<Integer> ints;

  public Data( int[] a ) {
    ints = new LinkedList<>(); 
    for( int i : a ) ints.add( i );
 }

 protected static interface Strategy{
    void do(int i);
 }

 protected void loop( Strategy s ) {
        for( int i : ints ) {
            s.do( i );
        }
    }
 }

Why am I getting this error? 为什么会出现此错误? Thank you very much in advance. 提前非常感谢您。

The method name do is a Java keyword (Section 3.9, JLS) and can't be a method name. 方法名称doJava关键字(第3.9节,JLS) ,不能是方法名称。 Change your method name to something not a keyword. 将您的方法名称更改为非关键字。

protected static interface Strategy{
    void doAction(int i);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM