假设我有这个注释类
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface MethodXY {
public int x();
public int y();
}
public class AnnotationTest {
@MethodXY(x=5, y=5)
public void myMethodA(){ ... }
@MethodXY(x=3, y=2)
public void myMethodB(){ ... }
}
Run Code Online (Sandbox Code Playgroud)
那么有没有办法查看一个对象,使用@MethodXY注释"寻找"该方法,其中元素x = 3,y = 2,并调用它?
谢谢
所以我有一个名为one.txt的文件,我多年来一直在master分支上进行修改.gitk one.txt将显示该特定文件的完整历史记录.但是在我更改one.txt => two.txt之后,gitk two.txt在重命名之前没有显示任何更改.
我尝试了gitk --follow two.txt,但只给出了每个提交的注释,但没有给出实际的文件更改信息.
我知道我可以执行git log - 关注two.txt,但是你必须将每个SHA1值gitk给每个被更改的内容.
那么任何提示?
def fibSeq(n: Int): List[Int] = {
var ret = scala.collection.mutable.ListBuffer[Int](1, 2)
while (ret(ret.length - 1) < n) {
val temp = ret(ret.length - 1) + ret(ret.length - 2)
if (temp >= n) {
return ret.toList
}
ret += temp
}
ret.toList
}
所以上面是我使用Scala生成一个Fibonacci序列的代码n
.我想知道Scala中是否有更优雅的方法可以做到这一点?
所以我有一个数据类型
data SomeType a =
Type a |
Mix (SomeType a) (SomeType a)
Run Code Online (Sandbox Code Playgroud)
这是SomeType的show实例
instance (Show a) => Show (SomeType a) where
show (Type a) = show a
show (Mix a b) = "(" ++ show a ++ " " ++ show b ++ ")"
Run Code Online (Sandbox Code Playgroud)
所以
Mix (Type 5) (Type 4)
Run Code Online (Sandbox Code Playgroud)
会给我的
(5 4)
Run Code Online (Sandbox Code Playgroud)
现在我想拥有
read "(3 4)" :: SomeType Int
Run Code Online (Sandbox Code Playgroud)
生产
(3 4)
Run Code Online (Sandbox Code Playgroud)
要么
read "(a b)" :: SomeType Char
Run Code Online (Sandbox Code Playgroud)
生产
(a b)
Run Code Online (Sandbox Code Playgroud)
我迷失在如何使用Read类.
假设我有两个飞镖项目
项目A包含使用Web组件创建一组UI小部件的代码(类似于https://github.com/kevmoo/widget.dart)
项目B包含我的前端代码,它将重用我在项目A中创建的UI小部件.
如果我不想将项目A发布到pub,那么无论如何都要将项目B链接到项目A而无需手动将项目A中的文件复制到B中?
谢谢
所以我想在Haskell中做一个简单的字符串反向函数
swapReverse :: String => String
swapReverse [x] = [x]
swapReverse [x,y] = [y,x]
swapReverse (x:xs:l) = -- pattern match fails here
let last = [l]
middle = xs
first = [x]
in last ++ swapReverse middle ++ first
Run Code Online (Sandbox Code Playgroud)
那么有没有办法在haskell中定义一个具有first
和last
元素的模式结构,以及middle
?中的所有元素?
string[] words = System.IO.File.ReadAllLines("word.txt");
var query = from word in words
where word.Length > "abe".Length && word.StartsWith("abe")
select word;
foreach (var w in query.AsParallel())
{
Console.WriteLine(w);
}
Run Code Online (Sandbox Code Playgroud)
基本上word.txt包含170000个英文单词.C#中的集合类是否比上述查询的字符串数组更快?将不会插入或删除,只搜索字符串以"abe"或"abdi"开头.
文件中的每个单词都是唯一的.
EDIT 1
在我的应用程序中,此搜索可能会执行数百万次.另外,我想坚持使用LINQ进行集合查询,因为我可能需要使用聚合函数.
EDIT 2
文件中的单词已经排序,文件不会更改
所以我在GHCI上有以下内容
>let addlist [] [] = []
>let addlist (a:as) (b:bs) = (a+b) : addlist as bs
>let x = [1..5]
>let y = [6..10]
>addlist x y
Run Code Online (Sandbox Code Playgroud)
最后一行给了我:[7,9,11,13,15***异常:: 1:5-49:函数addlist中的非详尽模式
我只是想把两个列表一起添加到一个列表...... :(
我做错了什么?
谢谢
我刚刚意识到如果你的C#应用程序使用LINQ-TO-SQL类来与数据库连接,你可以这样查询
using (DatabaseContext context = new DatabaseContext())
{
context.Log = Console.Out;
var query = from Person p in context.People
where person.Name == "john"
select p;
Console.WriteLine(query.Name);
}
Run Code Online (Sandbox Code Playgroud)
LINQ-TO-ENTITY中的等价物(这是ADO.NET的另一个名称吗?)
context.Log = Console.Out
或者还有另一种方法可以查看对数据库的实际SQL查询吗?
我有以下代码,应该很容易通过
public class Foo
{
public void FooHasAMethod()
{
Console.WriteLine("it is me, foo!!!");
}
}
public class Bar
{
public Foo FooProperty { get; set; }
}
public class FooBar
{
public static void Main()
{
Bar bar = new Bar{ FooProperty = new Foo() };
CallPropertyByName(bar, "Foo");
}
public static void CallPropertyByName(Bar bar, string propertyName)
{
PropertyInfo pi = bar.GetType().GetProperty(propertyName + "Property");
object fooObj = pi.GetValue(bar, null);
((Foo)fooObj).FooHasAMethod(); // this works
/* but I want to use
* ((Type.GetType(propertyName))fooObj).FooHasAMethod(); …
Run Code Online (Sandbox Code Playgroud) c# ×3
haskell ×3
reflection ×2
ado.net ×1
annotations ×1
casting ×1
collections ×1
dart ×1
dart-pub ×1
dart-webui ×1
fibonacci ×1
git ×1
gitk ×1
java ×1
linq ×1
recursion ×1
scala ×1
sequence ×1
typeclass ×1
types ×1