小编Rae*_*ald的帖子

ETag vs Header Expires

我环顾四周,但一直没能找出如果我应该使用了ETag 一个Expires头一个或另一个.

我要做的是确保我的Flash文件(以及其他图像以及当这些文件发生更改时不仅会更新.

我不想做任何特别的事情,例如更改文件名或在URL的末尾添加一些奇怪的字符以使其不被缓存.

另外,在我的PHP脚本中,我需要以编程方式执行任何操作以支持此操作,还是所有Apache?

etag caching http expires-header

354
推荐指数
5
解决办法
13万
查看次数

静态和非静态初始化代码块之间有什么区别

我的问题是静态关键字的一个特定用法.可以使用static关键字来覆盖不属于任何函数的类中的代码块.例如,以下代码编译:

public class Test {
    private static final int a;    
    static {
        a = 5;
        doSomething(a);
    }
    private static int doSomething(int x) {
        return (x+5);
    }
}
Run Code Online (Sandbox Code Playgroud)

如果你删除static它抱怨的关键字,因为变量afinal.但是,可以删除两个finalstatic关键字并使其编译.

这两种方式让我感到困惑.我怎么能有一个不属于任何方法的代码部分?如何调用它?一般来说,这种用法的目的是什么?或者更好,我在哪里可以找到关于此的文档?

java static static-initializer

345
推荐指数
8
解决办法
23万
查看次数

未定义的vtable参考

所以,我变得臭名昭着

未定义的引用'vtable ...

以下代码的错误(有问题的类是CGameModule.)我不能为我的生活理解问题所在.起初,我认为这与忘记给虚拟功能一个身体有关,但据我所知,一切都在这里.继承链有点长,但这里是相关的源代码.我不确定我应该提供哪些其他信息.

注意:构造函数是发生此错误的地方,看起来如此.

我的代码:

class CGameModule : public CDasherModule {
 public:
  CGameModule(Dasher::CEventHandler *pEventHandler, CSettingsStore *pSettingsStore, CDasherInterfaceBase *pInterface, ModuleID_t iID, const char *szName)
  : CDasherModule(pEventHandler, pSettingsStore, iID, 0, szName)
  { 
      g_pLogger->Log("Inside game module constructor");   
      m_pInterface = pInterface; 
  }

  virtual ~CGameModule() {};

  std::string GetTypedTarget();

  std::string GetUntypedTarget();

  bool DecorateView(CDasherView *pView) {
      //g_pLogger->Log("Decorating the view");
      return false;
  }

  void SetDasherModel(CDasherModel *pModel) { m_pModel = pModel; }


  virtual void HandleEvent(Dasher::CEvent *pEvent); 

 private:



  CDasherNode *pLastTypedNode;


  CDasherNode *pNextTargetNode;


  std::string m_sTargetString;


  size_t m_stCurrentStringPos;


  CDasherModel *m_pModel;


  CDasherInterfaceBase …
Run Code Online (Sandbox Code Playgroud)

c++ gcc g++

315
推荐指数
18
解决办法
47万
查看次数

如何获得所选单选按钮的值?

我到处寻找并试图从一组单选按钮中获取所选值.

这是我的HTML:

<div id="rates">
  <input type="radio" id="r1" name="rate" value="Fixed Rate"> Fixed Rate
  <input type="radio" id="r2" name="rate" value="Variable Rate"> Variable Rate
  <input type="radio" id="r3" name="rate" value="Multi Rate" checked="checked"> Multi Rate  
</div>
Run Code Online (Sandbox Code Playgroud)

这是我的.js:

var rates = document.getElementById('rates').value;
var rate_value;
if(rates =='Fixed Rate'){
    rate_value = document.getElementById('r1').value;

}else if(rates =='Variable Rate'){
    rate_value = document.getElementById('r2').value;

}else if(rates =='Multi Rate'){
    rate_value = document.getElementById('r3').value;
}  

document.getElementById('results').innerHTML = rate_value;
Run Code Online (Sandbox Code Playgroud)

我一直都没有定义.

html javascript radio-button

284
推荐指数
13
解决办法
109万
查看次数

258
推荐指数
3
解决办法
6万
查看次数

UTF-8 byte []到String

假设我刚刚使用a BufferedInputStream将UTF-8编码的文本文件的字节读入字节数组.我知道我可以使用以下例程将字节转换为字符串,但是这样做是否有更高效/更智能的方法,而不仅仅是迭代字节并转换每个字节?

public String openFileToString(byte[] _bytes)
{
    String file_string = "";

    for(int i = 0; i < _bytes.length; i++)
    {
        file_string += (char)_bytes[i];
    }

    return file_string;    
}
Run Code Online (Sandbox Code Playgroud)

java utf-8

237
推荐指数
3
解决办法
61万
查看次数

如果私有帮助方法可以是静态的,那么它们应该是静态的

假设我有一个旨在实例化的类.我在类中有几个私有的"帮助器"方法,它们不需要访问任何类成员,并且只对它们的参数进行操作,返回结果.

public class Example {
   private Something member;

   public double compute() {
       double total = 0;
       total += computeOne(member);
       total += computeMore(member);
       return total;         
   }

   private double computeOne(Something arg) { ... }
   private double computeMore(Something arg) {... } 
} 
Run Code Online (Sandbox Code Playgroud)

有没有特别的理由指定computeOnecomputeMore作为静态方法 - 或任何特殊原因不?

将它们保持为非静态是最容易的,即使它们肯定是静态的而不会引起任何问题.

java methods static static-methods

197
推荐指数
10
解决办法
8万
查看次数

查询与过滤器

我什么时候应该使用查询或过滤器或两者的组合,我看不到任何描述.他们之间有什么区别?有人可以解释一下吗?

elasticsearch

191
推荐指数
6
解决办法
5万
查看次数

将null返回为允许使用三元运算符的int,而不是if语句

让我们看看以下代码段中的简单Java代码:

public class Main {

    private int temp() {
        return true ? null : 0;
        // No compiler error - the compiler allows a return value of null
        // in a method signature that returns an int.
    }

    private int same() {
        if (true) {
            return null;
            // The same is not possible with if,
            // and causes a compile-time error - incompatible types.
        } else {
            return 0;
        }
    }

    public static void main(String[] args) {
        Main m = …
Run Code Online (Sandbox Code Playgroud)

java autoboxing nullpointerexception conditional-operator

185
推荐指数
5
解决办法
2万
查看次数

为什么显式抛出NullPointerException而不是让它自然发生?

在阅读JDK源代码时,我发现作者通常会检查参数是否为null,然后手动抛出新的NullPointerException().他们为什么这样做?我认为没有必要这样做,因为它会在调用任何方法时抛出新的NullPointerException().(这里是HashMap的一些源代码,例如:)

public V computeIfPresent(K key,
                          BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
    if (remappingFunction == null)
        throw new NullPointerException();
    Node<K,V> e; V oldValue;
    int hash = hash(key);
    if ((e = getNode(hash, key)) != null &&
        (oldValue = e.value) != null) {
        V v = remappingFunction.apply(key, oldValue);
        if (v != null) {
            e.value = v;
            afterNodeAccess(e);
            return v;
        }
        else
            removeNode(hash, key, null, false, true);
    }
    return null;
}
Run Code Online (Sandbox Code Playgroud)

java nullpointerexception

182
推荐指数
8
解决办法
1万
查看次数