# Julia- Warning Method definition is overwritten

**URL:** <https://discourse.julialang.org/t/julia-warning-method-definition-is-overwritten/3514>\
**Category:** General Usage\
**Tags:** question\
**Created:** [May 4, 2017, 12:52pm UTC](https://discourse.julialang.org/t/julia-warning-method-definition-is-overwritten/3514 "2017-05-04T12:52:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saran](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@Saran](https://discourse.julialang.org/u/Saran)\
**Post date:** [May 4, 2017, 12:52pm UTC](https://discourse.julialang.org/t/julia-warning-method-definition-is-overwritten/3514/1 "2017-05-04T12:52:39Z")

</div>

I the following warnings when i execute the code written below

> WARNING: Method definition (::Type{Main.Vector2D})(Real, Real) in  
> module Main at /…/juliaIntro.jl:13  
> overwritten at /…/juliaIntro.jl:13.  
> WARNING: Method definition (::Type{Main.Vector2D})(Any, Any) in module  
> Main at /…/juliaIntro.jl:13 overwritten  
> at /…/pythonlab/juliaIntro.jl:13.

And these warning are not consistent like it doesn’t show up for every execution, it randomly shows up. Sometimes the code just executes fine without any warning. Any pointers on why these warning are showing up. I am running Julia Version 0.5.1 on Mac 10.12.4

```
import Base.+

+(s1::String, s2::String) = string(s1, " ",s2)
println("Hello" + "World")

+(s1:: String, s2::Number) = s1 + " $s2"
+(s1:: Number, s2::String) = "$s1 " + s2
println("Hello World" + 46)
println(46 + "Hello World" + 46)

immutable Vector2D
  x::Real
  y::Real
end

v = Vector2D(3,5)
w = Vector2D(9.0,8.0)

println(v)
println(w)

```

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [May 4, 2017, 12:55pm UTC](https://discourse.julialang.org/t/julia-warning-method-definition-is-overwritten/3514/2 "2017-05-04T12:55:45Z")

</div>

This will happen if you re-evaluate this file in v0.5.x in the same Julia process since the methods will be be re-written. This is fixed in v0.6.

> [@Saran](#):
>
> immutable Vector2D  
> x::Real  
> y::Real  
> end

You probably want

```julia
immutable Vector2D{T1,T2}
  x::T1
  y::T2
end

```

or match the types:

```julia
immutable Vector2D{T}
  x::T
  y::T
end

```

Using a type parameter is good for performance. Using abstract types for fields is bad for performance.

---

<div class="post-metadata">

**Author:** ![Saran](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@Saran](https://discourse.julialang.org/u/Saran)\
**Post date:** [May 4, 2017, 1:10pm UTC](https://discourse.julialang.org/t/julia-warning-method-definition-is-overwritten/3514/3 "2017-05-04T13:10:27Z")

</div>

Thank You very much Chris. And also thanks for the tip on the performance front.
