【发布时间】:2017-10-10 17:58:16
【问题描述】:
这里我期望的是 Int 类型,但得到了 Float:
julia> function test()
i::Int = 3.0
end
test (generic function with 1 method)
julia> typeof(test())
Float64
在这种情况下,返回类型是 Int:
julia> function test()
i::Int = 3.0
i
end
test (generic function with 1 method)
julia> typeof(test())
Int64
这是正确的行为还是错误?
【问题讨论】:
-
一个陷阱,但不是一个错误。一个很好的例子,说明为什么显式返回语句通常是个好主意!
标签: julia