标签: anonymous

匿名函数中的PHP变量

我正在玩PHP中的匿名函数,并意识到它们似乎没有达到它们之外的变量.有没有办法解决这个问题?

例:

$variable = "nothing";

functionName($someArgument, function() {
  $variable = "something";
});

echo $variable;  //output: "nothing"
Run Code Online (Sandbox Code Playgroud)

这将输出"无".有没有办法匿名功能可以访问$variable

php variables anonymous function global-variables

106
推荐指数
1
解决办法
3万
查看次数

如何在Kotlin中创建匿名接口的实例?

我有一个第三方Java库,其对象具有如下界面:

public interface Handler<C> {
  void call(C context) throws Exception;
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能在Kotlin中简洁地实现它,就像这样的Java匿名类:

Handler<MyContext> handler = new Handler<MyContext> {
   @Override
   public void call(MyContext context) throws Exception {
      System.out.println("Hello world");
   }
}

handler.call(myContext) // Prints "Hello world"
Run Code Online (Sandbox Code Playgroud)

java lambda anonymous kotlin

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

如何使用匿名结构/联合编译C代码?

我可以用c ++/g ++做到这一点:

struct vec3 { 
    union {
        struct {
            float x, y, z;
        }; 
        float xyz[3];
    }; 
};
Run Code Online (Sandbox Code Playgroud)

然后,

vec3 v;
assert(&v.xyz[0] == &v.x);
assert(&v.xyz[1] == &v.y);
assert(&v.xyz[2] == &v.z);
Run Code Online (Sandbox Code Playgroud)

将工作.

如何使用gcc在c中执行此操作?我有

typedef struct {
    union {
        struct {
            float x, y, z;
        };
        float xyz[3];
    };
} Vector3;
Run Code Online (Sandbox Code Playgroud)

但我特别是周围都有错误

line 5: warning: declaration does not declare anything
line 7: warning: declaration does not declare anything
Run Code Online (Sandbox Code Playgroud)

c c++ struct anonymous unions

64
推荐指数
5
解决办法
8万
查看次数

WCFTestClient HTTP请求未经授权,客户端身份验证方案为"匿名"

我创建了一个WCF服务并将其部署在Server上.当我浏览这个服务时,它使用?wsdl URL给出了积极的回应.现在我正试图通过WCF测试客户端测试服务.它显示正确的元数据.但是当我尝试从服务中调用任何方法时,它会向我显示异常...这里是堆栈跟踪的错误细节.

HTTP请求未经授权,客户端身份验证方案为"匿名".从服务器收到的身份验证标头是"Negotiate,NTLM".

服务器堆栈跟踪:


System.ServiceModel.Channels.HttpChannelUtilities.ValidateAuthentication(HttpWebRequest请求,HttpWebResponse响应,WebException responseException,HttpChannelFactory factory)
HTTP请求未经授权使用客户端身份验证方案"Anonymous".从服务器收到的身份验证标头是"Negotiate,NTLM".

服务器堆栈跟踪:


System.ServiceModel.Channels.HttpChannelUtilities.ValidateAuthentication(HttpWebRequest请求,HttpWebResponse响应,WebException responseException,HttpChannelFactory工厂)

客户端绑定:

<bindings>
    <wsHttpBinding>
        <binding name="WSHttpBinding_IServiceMagicService" closeTimeout="00:01:00"
            openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
            bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
            maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
            messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
            allowCookies="false">
            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                maxBytesPerRead="4096" maxNameTableCharCount="16384" />
            <reliableSession ordered="true" inactivityTimeout="00:10:00"
                enabled="false" />
            <security mode="None">
                <transport clientCredentialType="Windows" proxyCredentialType="None"
                    realm="" />
                <message clientCredentialType="Windows" negotiateServiceCredential="true"
                    establishSecurityContext="true" />
            </security>
        </binding>
    </wsHttpBinding>
</bindings>
Run Code Online (Sandbox Code Playgroud)

服务器绑定:

<bindings>
  <wsHttpBinding>
    <binding name="WSHttpBinding_SEOService" closeTimeout="00:10:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" bypassProxyOnLocal="true" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="999524288" maxReceivedMessageSize="655360000" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
      <readerQuotas maxDepth="32" maxStringContentLength="900000" …
Run Code Online (Sandbox Code Playgroud)

wcf ntlm anonymous wcftestclient negotiate

63
推荐指数
5
解决办法
24万
查看次数

如何在java中用lambda替换匿名

我有这个代码,但IntelliJ告诉我用lambda替换匿名,但我不知道如何.谁能帮我这个?这是我的代码:

soundVolume.valueProperty().addListener(new ChangeListener<Number>() {
    public void changed(ObservableValue<? extends Number> ov,
                     Number old_val, Number new_val) {
        main.setSoundVolume(new_val.doubleValue());
        main.getMediaPlayer().setVolume(main.getSoundVolume());
    }
}); 
Run Code Online (Sandbox Code Playgroud)

java lambda anonymous

48
推荐指数
3
解决办法
5万
查看次数

如何通过Tor匿名贡献github?

我想匿名贡献给github上的项目.不要造成恶作剧,更多的是匿名捐款的精神.

在线匿名的首选工具似乎是TOR,它几乎适用于您在浏览器中可以执行的任何操作.但是,要在github上做出贡献,似乎有必要使用命令行界面或Mac应用程序.

如何通过Tor在此设置中引导我的git操作?我如何验证这实际上是发生了什么?

编辑:请注意假名(带有假电子邮件地址)和匿名(带有无法与身份相关联的IP地址)之间的区别.对github的伪名访问是微不足道的; 但是,我正在寻找匿名访问.

git privacy anonymous github tor

44
推荐指数
6
解决办法
1万
查看次数

我在C++中放置常量字符串:静态类成员还是匿名名称空间?

我需要定义一些仅由一个类使用的常量字符串.看起来我有三个选择:

  1. 将字符串直接嵌入到使用它们的位置.

  2. 将它们定义为类的私有静态常量成员:

    //A.h  
    class A {  
    private:  
       static const std::string f1;  
       static const std::string f2;  
       static const std::string f3;  
    };  
    
    //A.cpp  
    const std::string f1 = "filename1";  
    const std::string f2 = "filename2";  
    const std::string f3 = "filename3";  
    
    //strings are used in this file  
    
    Run Code Online (Sandbox Code Playgroud)
  3. 在cpp文件中的匿名命名空间中定义它们:

    //A.cpp  
    namespace {  
      const std::string f1 = "filename1";  
      const std::string f2 = "filename2";  
      const std::string f3 = "filename3";  
    }  
    
    //strings are used in this file  
    
    Run Code Online (Sandbox Code Playgroud)

鉴于这些选项,您会推荐哪一个?为什么?谢谢.

c++ string static namespaces anonymous

27
推荐指数
2
解决办法
1万
查看次数

C++ 11与非平凡成员的匿名联合

我正在更新我的结构,我想要添加一个std :: string成员.原始结构如下所示:

struct Value {
  uint64_t lastUpdated;

  union {
    uint64_t ui;
    int64_t i;
    float f;
    bool b;
  };
};
Run Code Online (Sandbox Code Playgroud)

当然,只是将一个std :: string成员添加到union会导致编译错误,因为通常需要添加该对象的非平凡构造函数. 在std :: string的情况下(来自informit.com的文本)

由于std :: string定义了所有六个特殊成员函数,因此U将具有隐式删除的默认构造函数,复制构造函数,复制赋值运算符,移动构造函数,移动赋值运算符和析构函数.实际上,这意味着除非您明确定义某些或所有特殊成员函数,否则无法创建U的实例.

然后该网站继续提供以下示例代码:

union U
{
int a;
int b;
string s;
U();
~U();
};
Run Code Online (Sandbox Code Playgroud)

但是,我在结构中使用匿名联合.我在freenode上问了## C++,他们告诉我这样做的正确方法是将构造函数放在struct中,并给我这个示例代码:

#include <new>

struct Point  {
    Point() {}
    Point(int x, int y): x_(x), y_(y) {}
    int x_, y_;
};

struct Foo
{
  Foo() { new(&p) Point(); }
  union {
    int z;
    double w;
    Point p;
  };
}; …
Run Code Online (Sandbox Code Playgroud)

c++ constructor anonymous unions c++11

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

在Java中,匿名类可以扩展另一个类吗?

代码如:

protected Interface1 varClass1 = new Interface1() {
Run Code Online (Sandbox Code Playgroud)

但我也希望这个匿名的嵌套类也扩展了类Base,如:

protected Interface1 varClass1 = new Interface1() extends Base {
....
Run Code Online (Sandbox Code Playgroud)

这在Java中可行吗?

java nested anonymous class extend

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

设置匿名类型属性名称

假设我有以下代码:

string SomeConst = "OtherName";
var persons = GetPersons(); //returns list of Person
var q = persons.Select(p => 
new
{
    SomeConst = p.Name
});
Run Code Online (Sandbox Code Playgroud)

基本上,我期望在q匿名类型与命名属性的序列中文别名,而不是SomeConst.我怎样才能实现这样的行为?

c# linq anonymous properties

23
推荐指数
1
解决办法
2万
查看次数