# Static types and statically typed

**URL:** <https://forum.golangbridge.org/t/static-types-and-statically-typed/9777>\
**Category:** Getting Help\
**Created:** [July 7, 2018, 9:17am UTC](https://forum.golangbridge.org/t/static-types-and-statically-typed/9777 "2018-07-07T09:17:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![taalhach](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/taalhach/32/4027_2.png) [@taalhach](https://forum.golangbridge.org/u/taalhach)\
**Post date:** [July 7, 2018, 9:17am UTC](https://forum.golangbridge.org/t/static-types-and-statically-typed/9777/1 "2018-07-07T09:17:05Z")

</div>

I am from java but now i am learning golang i have seen static types in java but i could not understand what STATIC is can anyone help me in understanding this concept in easy words and how does it relate to “golang is statically typed language” ?  
thanks

---

<div class="post-metadata">

**Author:** ![CurtGreen](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/curtgreen/32/4045_2.png) [@CurtGreen](https://forum.golangbridge.org/u/CurtGreen)\
**Post date:** [July 7, 2018, 9:29am UTC](https://forum.golangbridge.org/t/static-types-and-statically-typed/9777/2 "2018-07-07T09:29:25Z")

</div>

Golang being statically typed means that all variables you declare will have an unchanging type such as int, string, or some user defined type. Because of this there is no fuzzy type behavior where you can place an int value in code that expects a string hoping to get the string behavior of the int value. Can’t do it in go, but this makes the language much more error retardant.

Honestly to say you can’t do it isn’t true, you could use empty interface{} to design functions that could provide this behavior if you want it.

---

<div class="post-metadata">

**Author:** ![taalhach](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/taalhach/32/4027_2.png) [@taalhach](https://forum.golangbridge.org/u/taalhach)\
**Post date:** [July 7, 2018, 9:31am UTC](https://forum.golangbridge.org/t/static-types-and-statically-typed/9777/3 "2018-07-07T09:31:23Z")

</div>

Thanks @CurtGreen  
and static in java is same or it is something else ?

---

<div class="post-metadata">

**Author:** ![CurtGreen](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/curtgreen/32/4045_2.png) [@CurtGreen](https://forum.golangbridge.org/u/CurtGreen)\
**Post date:** [July 7, 2018, 9:33am UTC](https://forum.golangbridge.org/t/static-types-and-statically-typed/9777/4 "2018-07-07T09:33:46Z")

</div>

In Java the static keyword has a number of uses depending on its context, see this page: [https://www.geeksforgeeks.org/static-keyword-java/](https://www.geeksforgeeks.org/static-keyword-java/)

---

<div class="post-metadata">

**Author:** ![taalhach](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/taalhach/32/4027_2.png) [@taalhach](https://forum.golangbridge.org/u/taalhach)\
**Post date:** [July 7, 2018, 9:40am UTC](https://forum.golangbridge.org/t/static-types-and-statically-typed/9777/5 "2018-07-07T09:40:56Z")

</div>

this article was very helpful thanks a lot @CurtGreen

---

<div class="post-metadata">

**Author:** ![NobbZ](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/nobbz/32/3096_2.png) [@NobbZ](https://forum.golangbridge.org/u/NobbZ)\
**Post date:** [July 7, 2018, 11:05am UTC](https://forum.golangbridge.org/t/static-types-and-statically-typed/9777/6 "2018-07-07T11:05:51Z")

</div>

Java and Go are both statically typed, but this has nothing to do with the `static` keyword in Java (which in fact is different from the same keyword in C, which again is still statically typed).

So static typing simply means, that the type of each piece of data is known statically at compile time and can’t change.

Usually you also can’t change the type of a variable afterwards, but at least in Go, sometimes it feels as if you could, due to shadowing.

Both, Java and Go have some type that is a “supertype” of all others. In both cases, you can’t do much with those without doing runtime typechecks. In go you use typeassertions, in java you use `instanceof`.

In contrast to static typing there is dynamic typing, which basically means, that no types are known at compiletime but only at runtime. Most scripting languages use this kind of typing.

Also there are weak and strong typing. Those words explain how types are converted/coerced from one to the other. In strong typing data doesn’t get converted without making it explicit, while with weak typing some typeconversion happens implicitely (eg JavaScript where `1 + []` is possible and results in `"1"`).

Usually you classify a typesystem in a 2 dimensional grid using “weak/strong” on one axis, “static/dynamic” on the other.

---

<div class="post-metadata">

**Author:** ![taalhach](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/taalhach/32/4027_2.png) [@taalhach](https://forum.golangbridge.org/u/taalhach)\
**Post date:** [July 7, 2018, 11:16am UTC](https://forum.golangbridge.org/t/static-types-and-statically-typed/9777/7 "2018-07-07T11:16:52Z")

</div>

Thanks @NobbZ  
It was informative

---

<div class="post-metadata">

**Author:** ![system](https://forum.golangbridge.org/uploads/default/original/2X/5/5ad234f7c3dbc68b6cc72d338ce4f2973d9fd81c.png) [@system](https://forum.golangbridge.org/u/system)\
**Post date:** [October 5, 2018, 11:16am UTC](https://forum.golangbridge.org/t/static-types-and-statically-typed/9777/8 "2018-10-05T11:16:58Z")

</div>

Closed on October 5, 2018, 11:16am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
