在方法调用中传递当前对象是好/坏/可接受的做法.如:
public class Bar{
public Bar(){}
public void foo(Baz baz){
// modify some values of baz
}
}
public class Baz{
//constructor omitted
public void method(){
Bar bar = new Bar();
bar.foo(this);
}
}
Run Code Online (Sandbox Code Playgroud)
具体来说,线路是否bar.foo(this)可以接受?
我无法在书籍或网络上找到任何示例,描述如何通过名称正确初始化关联数组(使用空值) - 当然,除非这是正确的方式(?)
感觉好像还有另一种更有效的方法:
config.php文件
class config {
public static $database = array (
'dbdriver' => '',
'dbhost' => '',
'dbname' -> '',
'dbuser' => '',
'dbpass' => ''
);
}
// Is this the right way to initialize an Associative Array with blank values?
// I know it works fine, but it just seems ... longer than necessary.
Run Code Online (Sandbox Code Playgroud)
的index.php
require config.php
config::$database['dbdriver'] = 'mysql';
config::$database['dbhost'] = 'localhost';
config::$database['dbname'] = 'test_database';
config::$database['dbuser'] = 'testing';
config::$database['dbpass'] = 'P@$$w0rd';
// This code …Run Code Online (Sandbox Code Playgroud) 我需要生成一些随机的布尔值.但是我需要能够指定返回的概率true.结果如下:
private Random random = new Random();
random.nextBoolean();
Run Code Online (Sandbox Code Playgroud)
不管用.
一种可能的解决方案是:
private Random random = new Random()
public boolean getRandomBoolean(float p){
return random.nextFloat() < p;
}
Run Code Online (Sandbox Code Playgroud)
我想知道是否有更好或更自然的方式来做到这一点.
编辑:我想我在问是否有一个提供nextBoolean(浮点概率)方法的库类.
我为Vaadin/Hibernate/Spring项目创建了一个工作maven原型.我能够将这个原型安装到我的本地存储库并使用它来生成新的maven项目.
现在我想将原型部署到我的公司内部存储库,因此它可能被其他开发人员使用.但是,当我运行时,mvn deploy我收到以下错误消息:
[ERROR] Failed to execute goal org.apache.maven.plugins:
maven-deploy-plugin:2.7:deploy (default-deploy) on project
vaadin-hibernate-archetype: Failed to deploy artifacts/metadata:
No connector available to access repository maven.planet-ic.de
(maven.planet-ic.de/planet-ic-releases) of type default using the
available factories WagonRepositoryConnectorFactory -> [Help 1]
Run Code Online (Sandbox Code Playgroud)
是什么connector,我很想念?
编辑:我不是要求有人来解决我的问题,只是要了解一下'connector'是什么.
这是我的pom.xml,如果它应该是有趣的:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<groupId>de.planetic.maven.archetype.vaadin</groupId>
<artifactId>vaadin-hibernate-archetype</artifactId>
<version>1.1.0</version>
<packaging>jar</packaging>
<inceptionYear>2013</inceptionYear>
<description>
This archetype generates a Vaadin application for use with Hibernate, and to be deployed to a …Run Code Online (Sandbox Code Playgroud) 在使用django-rest-framework时,我在解析多部分表单数据时遇到了一些困难.我已经设置了一个最小视图来回显请求数据:
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.parsers import MultiPartParser, FormParser
class FileUpload(APIView):
parser_classes = (MultiPartParser, FormParser, )
def post(self, request, format=None, *args, **kwargs):
return Response({'raw': request.data, 'data': request._request.POST,
'files': str(request._request.FILES)})
Run Code Online (Sandbox Code Playgroud)
我期待的是raw(略严重命名我承认)包含有效的相同数据request._request.POST和request._request.FILES.
如果我POST对视图的Content-Type= application/x-www-form-urlencoded工作符合预期:
$ http -v --form POST http://localhost:8000/upload/api/ course=3 name=name
POST /upload/api/ HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 18
Content-Type: application/x-www-form-urlencoded; charset=utf-8
Host: localhost:8000
User-Agent: HTTPie/0.9.2
course=3&name=name
HTTP/1.0 200 OK
Allow: POST, …Run Code Online (Sandbox Code Playgroud) 同时使用htmlspecialchars和htmlentities会导致™符号甚至单'引号等项目的空白输出.显然,这绝对是无用的,但是在不使用html字符的情况下输出数据会导致这两个符号都出现.出现这种情况的原因是什么?
这是导致问题的代码:
<p>
<?php
echo nl2br(htmlspecialchars($aboutarray[0]['about_us'], ENT_COMPAT, "UTF-8"));
?>
</p>
Run Code Online (Sandbox Code Playgroud) 我正在使用NuSOAP尝试使用Java构建的Web服务.到目前为止我有这个代码:
<?php
require_once('lib/nusoap.php');
$wsdl="http://localhost:8080/HelloWorldWS/sayHiService?WSDL";
$client=new nusoap_client($wsdl, 'wsdl');
$param='John';#array('name'=>'John');
echo $client->call('Hey', $param);
unset($client);
?>
Run Code Online (Sandbox Code Playgroud)
但是当网页加载时,我得到一个空白页面甚至没有代码,我真的不知道为什么.难道我做错了什么?
我正在使用SHA1来加密密码.在我的原始代码中,我检查了密码字段是否为空:if(空($ newpassword)和(空($ newpassword2))){}
由于我现在使用SHA1并且当字段留空时它自动生成da39a3ee5e6b4b0d3255bfef95601890afd80709,我该如何重新编写代码?
将da39a3ee5e6b4b0d3255bfef95601890afd80709翻译回字符串?或者是其他东西?
请帮忙.
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
// oude password controle
if ($password == $qpassword)
$oudpassword_goed = 1;
// password controle
if ($newpassword == $newpassword2)
$newpassword_goed = 1;
if (empty($newpassword) and (empty($newpassword2)))
$newpassword_goed = 2;
// email controle
if ($email == $email2)
$email_goed = 1;
}
Run Code Online (Sandbox Code Playgroud) 继承如何与for-each循环相关?想象一下,我有两个课程:SubClass而且SuperClass,我有以下几个ArrayList.
/**
* Containes both SuperClass and SubClass instances.
*/
ArrayList<SuperClass> superClasses = new ArrayList<SuperClass>();
Run Code Online (Sandbox Code Playgroud)
是否可以superClasses以仅选择的方式进行迭代subClasses.
下列:
for(SubClass subClass : superClasses){
// Do Foo
}
Run Code Online (Sandbox Code Playgroud)
不这样做.以下是我唯一可以开展的工作:
for(SuperClass superClass : superClasses){
if(superClass instanceof SubClass){
// Do Foo
}
}
Run Code Online (Sandbox Code Playgroud)
但是我不想使用,instanceof除非绝对必要,因为我一直在阅读(StackOverflow,Oracle Tutorials等),人们几乎总能找到一个更好的解决方案来增加封装.有更优雅的方式吗?
php ×4
java ×3
arrays ×1
associative ×1
django ×1
encryption ×1
foreach ×1
html ×1
inheritance ×1
maven ×1
probability ×1
python ×1
random ×1
sha1 ×1
sql-update ×1
web-services ×1