# Strict typing and restricting types in a method's signature

**URL:** <https://discourse.julialang.org/t/strict-typing-and-restricting-types-in-a-methods-signature/645>\
**Category:** General Usage\
**Created:** [November 29, 2016, 3:21pm UTC](https://discourse.julialang.org/t/strict-typing-and-restricting-types-in-a-methods-signature/645 "2016-11-29T15:21:54Z")\
**Posts on this page:** 1\
**Showing post:** 23

<div class="post-metadata">

**Author:** ![greg\_plowman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/greg_plowman/32/8100_2.png) [@greg\_plowman](https://discourse.julialang.org/u/greg_plowman)\
**Post date:** [December 1, 2016, 1:49am UTC](https://discourse.julialang.org/t/strict-typing-and-restricting-types-in-a-methods-signature/645/23 "2016-12-01T01:49:30Z")

</div>

Could you use generated functions?  
Not sure if this is recommended, or indeed if it will work.

```julia
@generated function myfunc{T}(a::T)
    if method_exists(feature, (T,))
        :(_myfunc(a))
    else
        :(error("$T does not have feature"))
    end
end

function _myfunc(a)
    println("_myfunc called with $(typeof(a))")
end

feature(x::Number) = x*x

```

```julia

myfunc(2)
myfunc("cat")

```

---

_[View the full topic](https://discourse.julialang.org/t/strict-typing-and-restricting-types-in-a-methods-signature/645)._
