zoukankan      html  css  js  c++  java
  • dart基础---->函数传值

    1. string type

    main(List<String> args) {
      String name = "huhx";
      changIt(name);
      print('after: $name'); // after: huhx
    }
    
    void changIt(String name) {
      print('before: $name'); // before: huhx
      name = "linux";
    }
    

    2. reference Type

    class User {
      String name;
    
      User(this.name);
    }
    
    main(List<String> args) {
      User user = User("huhx");
      changIt(user);
      print('after: ${user.name}'); // after: linux
    }
    
    void changIt(User user) {
      print('before: ${user.name}'); // before: huhx
      user.name = "linux";
    }
    

    3. deep clone

    import 'dart:convert';
    
    class User {
      String name;
    
      User(this.name);
    
      factory User.fromJson(Map<String, dynamic> userMap) => User(userMap['name']);
    
      Map<String, dynamic> toJson() => {'name': this.name};
    
      User clone() {
        final String jsonString = json.encode(this);
        final jsonResponse = json.decode(jsonString);
    
        return User.fromJson(jsonResponse as Map<String, dynamic>);
      }
    }
    
    main(List<String> args) {
      User user = User("huhx");
      changIt(user);
      print('after: ${user.name}'); // after: huhx
    }
    
    void changIt(User user) {
      User temp = user.clone();
      // User temp = user; then: after linux
      print('before: ${temp.name}'); // before: huhx
      temp.name = "linux";
    }
    

  • 相关阅读:
    巡风安装配置 -windows
    Struts2-052 RCE CVE-2017-9805
    CVE-2017-12615和CVE-2017-12616
    Nmap使用指南
    理解HTTP协议
    缓慢拒绝服务攻击- slowloris.pl
    SSL&TLS渗透测试
    Nmap版本检测
    Protocol Buffer学习教程之编译器与类文件(三)
    64位Windows系统下32位应用程序连接MySql
  • 原文地址:https://www.cnblogs.com/huhx/p/13366668.html
Copyright © 2011-2022 走看看