groovy(grails)会给你编译时间检查像java吗? [英] Will groovy (grails) give you compile time checking like java?

查看:81
本文介绍了groovy(grails)会给你编译时间检查像java吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Groovy(grails)会给你编译时间检查像java吗?

如果你总是指定类型,这会改变什么吗?

解决方案

Groovy编译器当然会发现语法错误,但几乎没有像Java那样的类型错误。即使使用未声明的变量也会通过编译。



声明类型将增加已完成检查的数量,但不会太多。



这是因为Groovy是一种具有强大元编程功能的动态语言,它使编译器无法知道例如在编译时给定的对象会有什么方法或字段,因为这可能会在运行时被其他代码改变。

然而,IDE插件提供了一个折衷方案,将具有声明类型的变量的成员标记为类声明中不存在的可能错误。然后开发者可以决定这个成员是否会在运行时出现,或者他是否犯了一个错字。此外,已知的类成员会以自动完成方式出现。


Will groovy (grails) give you compile time checking like java?

If you always specify the type, will that change things much?

解决方案

The Groovy compiler will of course find syntax errors, but almost no type errors as with Java. Even the use of undeclared variables will often pass compilation.

Declaring types will increase the amount of checking that is done, but not by much.

This is because Groovy is a dynamic language with powerful metaprogramming features that make it impossible for the compiler to know e.g. what methods or fields a given object will have at compile time, since it's possible for this to be changed at runtime by other code.

However, IDE plugins offer a compromise by marking members of variables with a declared type that are not present in the class declaration as possible errors. Then the developer can decide whether this member will be present at runtime, or whether he just made a typo. Additionally, known class members appear in autocompletion.

这篇关于groovy(grails)会给你编译时间检查像java吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆