What is this "def" I heard of?
"def" is a replacement for a type name. In variable definitions it is used to indicate that you don't care
about the type. In variable definitions it is mandatory to either provide a type name explicitly or to use
"def" in replacement. This is needed to the make variable definitions detectable for the Groovy parser.
These definitions may occur for local variables in a script or for local variables and properties/fields in a
class.
Rule of thumb
You can think of "def" as an alias of "Object" and you will understand it in an instant.
Future Groovy may give "def" an additional meaning in terms of static and dynamic typing. But this is
post Groovy 1.0.
"def" can also replace "void" as the return type in a method definiton.
-
defdynamic=1
-
dynamic="IamaStringstoredinavariableofdynamictype"
-
inttyped=2
-
typed="IamaStringstoredinavariableoftypeint??"
The assignment of a string, to a variable of type int will fail. A variable typed with "def" allows this.
分享到:
相关推荐
【教案名称】:幼儿园2021年中班英语教案 - 歌曲《What is this?》 【教案概述】: 本教案旨在帮助幼儿园中班的孩子们学习基本的英语对话,通过歌曲《What is this?》的教学,让他们掌握询问与回答物品是什么的英语...
[2] What is this .xxx file type? Where can I find the corresponding compression program? [3] What is the latest pkzip version? [4] What is an archiver? [5] What is the best general purpose ...
【中班英语:Song What is this.doc】是一个适合幼儿园中班儿童学习的英语教学资源,主要目的是教授孩子们基本的英语对话技巧,特别是围绕"What is this?"这个常见的询问句型进行交流。活动通过歌曲的形式,让孩子们...
Is This the Right Book for You? 1 Why Are There So Many Footnotes? 2 What About the Exercises and Their Answers? 3 What Do Those Numbers Mean at the Start of the Exercise? 4 What If I’m a Perl Course...
whatisthis学习课程.pptx
这篇资料是针对小学三年级上册英语的一份同步练习,主题为Lesson6的"What is this?"。这份练习旨在帮助学生巩固和提升他们的英语基础,特别是字母识别、单词拼写、词汇理解以及基本的对话交流能力。 一、在第一部分...
计算机专业英语学习课件,包含文本与图片,非常有用哟
这篇教育资源是针对三年级上册英语课程的同步练习,主要涵盖了Lesson 6 "What is this?" 的主题。这个单元的学习目标是提升学生的词汇识别能力、基本的英汉互译技巧以及情境对话的理解和应用。 在第一部分练习中,...
Whatisthis公开课PPT教案学习.pptx
这篇资料是针对小学三年级上册英语课程的同步练习,主题为"Lesson 6 What is this?",主要训练学生的英语词汇识别、翻译以及对话应用能力。以下是详细的解释和知识点: 一、根据图片写单词: 这部分练习旨在让学生...
What Knowledge Is Important to a Software Professional?——by Timothy C.Lethbridge 作者来自University of Ottawa,这篇文章影响很大,非常值得软件工程专业人士研读。
This book is an introduction to the art and science of implementing mathematical models of optimization problems. An optimization problem is almost any problem that is, or can be, formulated as a ...
What is SSAE 16, ISAE3402
(a) filling in skeleton tables of the database with examples of what is to be retrieved (b) placing SQL keywords, such as select, under the column names they want to retrieve (c) typing a ...
本书详细介绍了数学的各个分支。对于有需要了解数学方法的程序员有很大的帮助。
【Unit 6 What colour is this balloon 练习题2】主要涵盖了英语听力、词汇拼写、选择题以及造句四个部分,旨在帮助学生巩固和提升关于颜色和物体名称的英语知识。 一、听音,画画并涂色 这部分练习旨在通过实际...
餐廳常用英文 1 Can I help you ? / May I help you ? / What can I get for you today ? 2 May / Can I take your order ? 您要吃點什麼? 3 What will it be ? 您要點什麼?... / What kind of drinks ?