What is the difference between import . "package" and import _ "package" in Go?

  • import . "package" allows referring to package symbols without package name prefix whereas import _ "package" only imports the package for its side effects without making its symbols accessible
  • import . "package" only imports the package for its side effects without making its symbols accessible whereas import _ "package" allows referring to package symbols without package name prefix
  • import _ "package" allows referring to package symbols without package name prefix whereas import . "package" imports the package for its side effects without making its symbols accessible
  • import _ "package" imports the package for its side effects without making its symbols accessible whereas import . "package" allows referring to package symbols without package name prefix
The import . "package" statement allows you to refer to the symbols in the imported package without prefixing them with the package name. On the other hand, import _ "package" imports the package solely for its side effects, such as initializing global variables or registering functions, without making its symbols directly accessible in the code.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *