# Overwrite default constructor

**URL:** <https://discourse.julialang.org/t/overwrite-default-constructor/59520>\
**Category:** New to Julia\
**Created:** [April 18, 2021, 6:11am UTC](https://discourse.julialang.org/t/overwrite-default-constructor/59520 "2021-04-18T06:11:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![oyczyco13](https://avatars.discourse-cdn.com/v4/letter/o/dec6dc/32.png) [@oyczyco13](https://discourse.julialang.org/u/oyczyco13)\
**Post date:** [April 18, 2021, 6:11am UTC](https://discourse.julialang.org/t/overwrite-default-constructor/59520/1 "2021-04-18T06:11:02Z")

</div>

Is it possible to overwrite the default constructor like:

```julia
struct A
       field1
       field2
       field3
end

function A(f1, f2, f3)
       # do some operation here like log / parameters inspection
       # return a new instance here
end

```

I don’t actually know how to create a new instance, if I call A then it ends up an infinite recursion.

---

<div class="post-metadata">

**Author:** ![yoninazarathy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yoninazarathy/32/10086_2.png) [@yoninazarathy](https://discourse.julialang.org/u/yoninazarathy)\
**Post date:** [April 18, 2021, 6:30am UTC](https://discourse.julialang.org/t/overwrite-default-constructor/59520/2 "2021-04-18T06:30:21Z")

</div>

Yes. See the [documentation for inner constructors](https://docs.julialang.org/en/v1/manual/constructors/#man-inner-constructor-methods). So for example in your case,

```julia
struct A
           field1
           field2
           field3
           function A(f1,f2,f3)
               return new(f1, f1+f2, f1*f3)
           end
end

```

---

<div class="post-metadata">

**Author:** ![oyczyco13](https://avatars.discourse-cdn.com/v4/letter/o/dec6dc/32.png) [@oyczyco13](https://discourse.julialang.org/u/oyczyco13)\
**Post date:** [April 18, 2021, 6:30am UTC](https://discourse.julialang.org/t/overwrite-default-constructor/59520/3 "2021-04-18T06:30:42Z")

</div>

Many thanks
