<i id='9YE3U'><tr id='9YE3U'><dt id='9YE3U'><q id='9YE3U'><span id='9YE3U'><b id='9YE3U'><form id='9YE3U'><ins id='9YE3U'></ins><ul id='9YE3U'></ul><sub id='9YE3U'></sub></form><legend id='9YE3U'></legend><bdo id='9YE3U'><pre id='9YE3U'><center id='9YE3U'></center></pre></bdo></b><th id='9YE3U'></th></span></q></dt></tr></i><div id='9YE3U'><tfoot id='9YE3U'></tfoot><dl id='9YE3U'><fieldset id='9YE3U'></fieldset></dl></div>
  • <legend id='9YE3U'><style id='9YE3U'><dir id='9YE3U'><q id='9YE3U'></q></dir></style></legend>
        <bdo id='9YE3U'></bdo><ul id='9YE3U'></ul>

        <tfoot id='9YE3U'></tfoot>

        <small id='9YE3U'></small><noframes id='9YE3U'>

        无法实例化类型 Set

        Cannot instantiate the type Set(无法实例化类型 Set)
          <tbody id='slGYQ'></tbody>

        <tfoot id='slGYQ'></tfoot>
      1. <small id='slGYQ'></small><noframes id='slGYQ'>

        • <i id='slGYQ'><tr id='slGYQ'><dt id='slGYQ'><q id='slGYQ'><span id='slGYQ'><b id='slGYQ'><form id='slGYQ'><ins id='slGYQ'></ins><ul id='slGYQ'></ul><sub id='slGYQ'></sub></form><legend id='slGYQ'></legend><bdo id='slGYQ'><pre id='slGYQ'><center id='slGYQ'></center></pre></bdo></b><th id='slGYQ'></th></span></q></dt></tr></i><div id='slGYQ'><tfoot id='slGYQ'></tfoot><dl id='slGYQ'><fieldset id='slGYQ'></fieldset></dl></div>
            <legend id='slGYQ'><style id='slGYQ'><dir id='slGYQ'><q id='slGYQ'></q></dir></style></legend>

              • <bdo id='slGYQ'></bdo><ul id='slGYQ'></ul>

                  本文介绍了无法实例化类型 Set的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试创建一组字符串,其中填充了来自 Hashtable 的键,因此 for-each 循环可以遍历 Set 并将默认值放入 Hashtable.我仍在学习 Java,但我尝试这样做的方式不是有效的语法.有人可以证明这样做的正确方法,并解释为什么我的方法行不通,而他们的方法行得通.

                  I am trying to create a Set of Strings which is filled with the keys from a Hashtable so a for-each loop can iterate through the Set and put defaults in a Hashtable. I am still learning Java but the way I am trying to do it isn't valid syntax. Could someone please demonstrate the proper way of doing this and explain why my way doesn't work and theirs does.

                  private Hashtable<String, String> defaultConfig() {
                      Hashtable<String, String> tbl = new Hashtable<String, String>();
                      tbl.put("nginx-servers","/etc/nginx/servers");
                      tbl.put("fpm-servers","/etc/fpm/");
                      tbl.put("fpm-portavail","9001");
                      tbl.put("webalizer-script","/usr/local/bin/webalizer.sh");
                      tbl.put("sys-useradd","/sbin/useradd");
                      tbl.put("sys-nginx","/usr/sbin/nginx");
                      tbl.put("sys-fpmrc","/etc/rc.d/php_fpm");
                      tbl.put("www-sites","/var/www/sites/");
                      tbl.put("www-group","www"); 
                      return tbl;
                  }
                  
                  //This sets missing configuration options to their defaults.
                  private void fixMissing(Hashtable<String, String> tbl) {
                      Hashtable<String, String> defaults = new Hashtable<String, String>(defaultConfig());
                      //The part in error is below...
                      Set<String> keys = new Set<String>(defaults.keySet());
                  
                      for (String k : keys) {
                          if (!tbl.containsKey(k)) {
                              tbl.put(k, defaults.get(k));
                          }
                      }
                  }
                  

                  推荐答案

                  Set 不是一个类,它是一个接口.

                  Set is not a class, it is an interface.

                  所以基本上你只能实例化实现 Set 的类(HashSetLinkedHashSetTreeSet)

                  So basically you can instantiate only class implementing Set (HashSet, LinkedHashSet orTreeSet)

                  例如:

                  Set<String> mySet = new HashSet<String>();
                  

                  这篇关于无法实例化类型 Set的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Compiling C++ for the JVM(为 JVM 编译 C++)
                  Compile to java bytecode (without using Java)(编译成java字节码(不使用Java))
                  How to drive C#, C++ or Java compiler to compute 1+2+3+...+1000 at compile time?(如何在编译时驱动 C#、C++ 或 Java 编译器计算 1+2+3+...+1000?)
                  Java ClassLoader: load same class twice(Java ClassLoader:两次加载相同的类)
                  How to debug .class files in ECLIPSE?(如何在 ECLIPSE 中调试 .class 文件?)
                  Java quot;The blank final field may not have been initializedquot; Anonymous Interface vs Lambda Expression(Java“可能尚未初始化空白的最终字段匿名接口与 Lambda 表达式)

                  <legend id='qLx7L'><style id='qLx7L'><dir id='qLx7L'><q id='qLx7L'></q></dir></style></legend>
                    <tbody id='qLx7L'></tbody>
                    <bdo id='qLx7L'></bdo><ul id='qLx7L'></ul>

                    <small id='qLx7L'></small><noframes id='qLx7L'>

                  • <tfoot id='qLx7L'></tfoot>

                      • <i id='qLx7L'><tr id='qLx7L'><dt id='qLx7L'><q id='qLx7L'><span id='qLx7L'><b id='qLx7L'><form id='qLx7L'><ins id='qLx7L'></ins><ul id='qLx7L'></ul><sub id='qLx7L'></sub></form><legend id='qLx7L'></legend><bdo id='qLx7L'><pre id='qLx7L'><center id='qLx7L'></center></pre></bdo></b><th id='qLx7L'></th></span></q></dt></tr></i><div id='qLx7L'><tfoot id='qLx7L'></tfoot><dl id='qLx7L'><fieldset id='qLx7L'></fieldset></dl></div>