# Overriding a method in a different module

**URL:** <https://discourse.julialang.org/t/overriding-a-method-in-a-different-module/5805>\
**Category:** General Usage\
**Created:** [September 10, 2017, 3:26am UTC](https://discourse.julialang.org/t/overriding-a-method-in-a-different-module/5805 "2017-09-10T03:26:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [September 10, 2017, 3:26am UTC](https://discourse.julialang.org/t/overriding-a-method-in-a-different-module/5805/1 "2017-09-10T03:26:59Z")

</div>

Hi everyone, I am having trouble calling a method that I have overridden. Here is an example:

```nohighlight
module XXX
    export hello
	function hello()
		println("XXX")
	end
end

using XXX

t = function XXX.hello()
    println("yyy")
end

t()

```

The result is:

```julia
WARNING: Method definition hello() in module XXX at test/overr.jl:4 overwritten in module Main at test/overr.jl:11.
ERROR: LoadError: MethodError: objects of type Void are not callable
Stacktrace:
 [1] include_from_node1(::String) at ./loading.jl:569
 [2] include(::String) at ./sysimg.jl:14
 [3] process_options(::Base.JLOptions) at ./client.jl:305
 [4] _start() at ./client.jl:371
while loading test/overr.jl, in expression starting on line 14

```

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [September 10, 2017, 5:17am UTC](https://discourse.julialang.org/t/overriding-a-method-in-a-different-module/5805/2 "2017-09-10T05:17:10Z")

</div>

method definition in that form do not return a value. Just call the function direction or assign the function explicitly to the variable.

---

<div class="post-metadata">

**Author:** ![Qiyamah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qiyamah/32/2660_2.png) [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Post date:** [September 10, 2017, 9:55am UTC](https://discourse.julialang.org/t/overriding-a-method-in-a-different-module/5805/3 "2017-09-10T09:55:11Z")

</div>

What do you mean?  
can you show me a code example?  
Thanks

---

<div class="post-metadata">

**Author:** ![rfourquet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rfourquet/32/3610_2.png) [@rfourquet](https://discourse.julialang.org/u/rfourquet)\
**Post date:** [September 10, 2017, 10:18am UTC](https://discourse.julialang.org/t/overriding-a-method-in-a-different-module/5805/4 "2017-09-10T10:18:05Z")

</div>

It means `typeof(function XXX.hello() ...end) == Void`, so when you assigned to `t`, it gets the value `nothing`, hence cannot be called. So @yuyichao was suggesting to either call directly `XXX.hello()`, or to assign the function to a variable like in `t = XXX.hello` before calling `t()`.

That said, I don’t know why this form of method definition unexpectedly returns `nothing` rather than the function.

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [September 10, 2017, 12:46pm UTC](https://discourse.julialang.org/t/overriding-a-method-in-a-different-module/5805/5 "2017-09-10T12:46:10Z")

</div>

It looks like you’re accidentally using R syntax to define a function.

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [September 10, 2017, 7:12pm UTC](https://discourse.julialang.org/t/overriding-a-method-in-a-different-module/5805/6 "2017-09-10T19:12:10Z")

</div>

```julia
julia>	module XXX
	export hello
	function hello()
		println("XXX")
	end
	end

julia> using XXX

julia>	t = function XXX.hello()
		println("yyy")
	end

julia> typeof(t)
Void

julia>	XXX.hello()
yyy

```
