zoukankan      html  css  js  c++  java
  • the diference between include and import

    There is an interesting article here regarding the difference between import and `include when it comes to packages. I'm going to attempt to summarise it here.

    When you `include a file, it is basically saying take the contents of that file and paste it at the location of the include statement. This is effectively the same behaviour as #include in C/C++.

    Great you are thinking, now we have everything in the file, why can't we just use it? Imagine the case though where you are declaring a package in SV. If you `include a file containing a class A into two different packages P and Q, you are basically making a different copy of it in each package, which because of the way SV handles types will be incompatible (you now have one class called P::A and another called Q::A).

    This is where import comes in. Unlike `include, the import statement does not copy the definitions being brought in to the file, instead it simply makes them visible. This is similar to the way the using namespace works in C++. Lets say you still `include the class A in package P as before. But now, rather than including A directly in package Q, you import P::A instead, both P and Q now contain the same class P::A instead of having two different ones.

    So in summary:

    • `include copies the contents of the file in making a local copy of any classes/types/etc.
    • import doesn't copy but rather makes the existing package declarations visible in the current file

    Consider one question, how to address scope visibility of identifier

    import content should be compiled once; while include content should not be compiled

    import is statement which must be followed by simicolon, include is preprocessor indirective which not need

    the class and type which is include at diffrent place, will not be treated as the same object, while import assure the 

    coherence

     

  • 相关阅读:
    elasticsearch:shard 和 replica 机制
    zookeeper 的 docker 镜像使用
    zookeeper 图形化的客户端工具:ZooInspector
    zookeeper 学习资料
    Spring Cloud 与 Dubbo、Spring Cloud 与 Docker、Spring Cloud 与 Kubernetes 比较
    可视化界面:ElasticSearch Head,最方便的是直接下载谷歌浏览器扩展程序
    java 中 heap(堆)和stack(栈)的区别
    Elasticsearch 学习资料
    025_lua脚本语言
    004_zookeeper运维之maxClientCnxns overflow
  • 原文地址:https://www.cnblogs.com/air-of-code/p/10478735.html
Copyright © 2011-2022 走看看