我的Eclipse上发生了什么?在所有内容上获取语法错误

时间:2016-12-27 11:56:51

标签: java syntax

这是我的简单代码,但它有4个语法错误。

(require 'cl-async)
(require 'babel)

(defun my-tcp-server ()
  (format t "Starting server.~%")
    (as:tcp-server
     nil 8888  ; nil means 0.0.0.0 to listen for any address
     ;; read-cb
     (lambda (socket data)
       (let ((data-str ; stores the received data in utf8 string
          (handler-case (babel:octets-to-string data :encoding :utf-8)
        (babel-encodings:invalidutf8-continuation-byte (err)
          (declare (ignore err))
          (format nil "^@~%")))))
     ;; exits if received "bye"
     (cond ((equal "bye" (string-right-trim '(#\Return #\Newline) data-str))
        (as:close-socket socket)
        (format t "Client disconnected.~%"))
           (t (format t "~a" data-str) ; echo on the server side
          (as:write-socket-data socket "Send to server > ")))))
     ;; handle SIGINT
     :event-cb (as:signal-handler 2 (lambda (sig)
                      (declare (ignore sig))
                      (as:free-signal-handler 2)
                      (as:exit-event-loop)))
     :connect-cb (lambda (socket)
           (format t "Client connected.~%")
           (as:write-socket-data socket "Send to server > "))))

(as:start-event-loop #'my-tcp-server)

包含所有信息的屏幕截图:Click

1 个答案:

答案 0 :(得分:0)

您无法在类中完全执行代码。您可以在方法或某个声明中执行此操作。

例如,您可以使用main方法执行此代码,如下所示:

public class Program {
    public static void main(String[] args) {
        System.out.print("Hello World");
    }
}

或者你可以像这样在静态语句中执行代码:

public class Program {
    static {
        System.out.println("Hello World 1");
    }

    public static void main(String[] args) {
        System.out.print("Hello World 2");
    }
}

请记住,静态语句在main方法之前执行。

希望,它帮助了你。