# Bypass inner constructor / call \`new\` outside inner constructor

**URL:** <https://discourse.julialang.org/t/bypass-inner-constructor-call-new-outside-inner-constructor/112142>\
**Category:** General Usage\
**Tags:** constructors\
**Created:** [March 26, 2024, 1:37pm UTC](https://discourse.julialang.org/t/bypass-inner-constructor-call-new-outside-inner-constructor/112142 "2024-03-26T13:37:56Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [March 26, 2024, 2:36pm UTC](https://discourse.julialang.org/t/bypass-inner-constructor-call-new-outside-inner-constructor/112142/4 "2024-03-26T14:36:57Z")

</div>

Another option is to use `reinterpret`. I like this method because it emphasizes the danger of bypassing the inner constructor checks:

```julia
struct OrderedPair{T <: Real}
    x::T
    y::T
    OrderedPair(x, y) = x > y ? error("out of order") : 
      new{promote_type(typeof(x),typeof(y))}(x,y)
end

```

with this definition, the normal construction works as expected:

```julia
julia> OrderedPair(1,2)
OrderedPair{Int64}(1, 2)

julia> OrderedPair(1,2.2)
OrderedPair{Float64}(1.0, 2.2)

julia> OrderedPair(2,1)
ERROR: out of order

```

And the unsafe construction can be done as follows:

```julia
julia> reinterpret(OrderedPair{Int}, [2,1])[1]
OrderedPair{Int64}(2, 1)

```

---

_[View the full topic](https://discourse.julialang.org/t/bypass-inner-constructor-call-new-outside-inner-constructor/112142)._
